• Godot Help2D
  • [GODOT 4.1] .gd file bar not appearing in area2d's inspector tab

SuperGibaLogan sigh
you are using SPACES, do you not understand the difference?

gdscript uses TABS for defining pretty much everything, indentation and syntax are very much important, this isn't C# where you can skip the brackets.

    xyz so i did try to rewrite but it still gave me errors, im also thinking of searching up a pathfinding tutorial and remake the code entirely

      xyz right here:

      extends Area2D
      
      var current_scatter_index = 0
      
      @export var speed = 75
      @export var movement_targets = Resource
      @export var tile_map = TileMap
      @export var navigation_area_2d = $NavigationAgent2D
      
      func _ready():
       navigation_area_2d.path_desired_distance = 4.0
       navigation_area_2d.target_desired_distance = 4.0
       navigation_area_2d.target_reached.connect(on_position_reached)
       
       call_deferred("setup")
       
      func _process(delta):
       move_ghost(navigation_area_2d.get_next_path_position(), delta)
      
      func move_ghost(next_position Vector2 delta float):	
      	var current_ghost_position = global_position
      	var new_velocity = (next_position - current_ghost_position).normalized()
      
      
      
       
      func setup():
       navigation_area_2d.set_navigation_map(tile_map.get_navigation_map(0))
       NavigationServer2D.agent_set_map(navigation_area_2d.get_rid(), tile_map.get_navigation_map(0))
      func scatter():
       navigation_area_2d.target_position = movement_targets.scatter_targets[current_scatter_index].position
      func on_position_reached():
       if current_scatter_index < 3:
        current_scatter_index += 1
       else:
        current_scatter_index = 0
      • xyz replied to this.

        SuperGibaLogan You need to put tabs instead of spaces for all block indentations as you did in move_ghost function. The script editor will display tabs as those subtle arrow thingies:

        You can see it in the tutorial as well, that's how you know the instructor (or you) inserted a tab character there by pressing the tab key, not space. The number of tabs at the start of each line determines to which code block the line belongs. In GDScript similar to Python this indentation is used to structure the code. The structure affects the execution flow so take care not to mess it up there. One wrong tab and the code may not be working as intended.

          xyz so i putted tabs

          extends Area2D
          
          var current_scatter_index = 0
          
          @export var speed = 75
          @export var movement_targets = Resource
          @export var tile_map = TileMap
          @export var navigation_area_2d = $NavigationAgent2D
          
          func _ready():
          	navigation_area_2d.path_desired_distance = 4.0
          	navigation_area_2d.target_desired_distance = 4.0
          	navigation_area_2d.target_reached.connect(on_position_reached)
           
          call_deferred("setup")
           
          func _process(delta):
          	move_ghost(navigation_area_2d.get_next_path_position(), delta)
           
          
          func move_ghost(next_position Vector2 delta float):
          	var current_ghost_position = global_position
          	var new_velocity = (next_position - current_ghost_position).normalized()
          
          
          func setup():
          	navigation_area_2d.set_navigation_map(tile_map.get_navigation_map(0))
          	NavigationServer2D.agent_set_map(navigation_area_2d.get_rid(), tile_map.get_navigation_map(0))
           
           
          func scatter():
          	navigation_area_2d.target_position = movement_targets.scatter_targets[current_scatter_index].position
           
          func on_position_reached():
          	 if current_scatter_index < 3:
          		current_scatter_index += 1
          	else:
          		 current_scatter_index = 0
          • xyz replied to this.

            SuperGibaLogan That call_deferred line should also be indented with the function body it belongs to. You can't have any code outside of functions, except variable declarations.

              xyz should the call_deferred line be in the func setup(): line?

              • xyz replied to this.

                SuperGibaLogan should the call_deferred line be in the func setup(): line?

                How would I know 🙂? Look where they've put it in the tutorial.