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

xyz i see, but the tutorial im using is the only tutorial i could find that does all the gameplay mechanics perfectly
also i typed the code, not copy and paste it (my code isnt fininshed yet just so you know)

    SuperGibaLogan im currently thinking of ways on how to fix the errors, im also looking at the errors listed in the syntax to think of ways to fix the errors, also, would it be ok if i could show the entire code and also show the errors listed?

    • xyz replied to this.

      SuperGibaLogan would it be ok if i could show the entire code and also show the errors listed?

      Of course. You should have done that right away.

      At this point you shouldn't really worry about gameplay mechanics. Learn the programming basics first following the simplest introductory tutorials.

        xyz alright then
        heres the code:

        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

        and these are the errors listed (i figured out most of them but i tried to remove the comma and colon from line 20 but it still shows the error):
        Line 20:Expected closing ")" after function parameters.
        Line 20:Expected ":" after function declaration.
        Line 20:Expected end of statement after expression, found "Identifier" instead.

          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.

                          xyz ok lemme see
                          it said to put it in the func ready statement so i did

                          • xyz replied to this.

                            SuperGibaLogan Yay! Now the code is at least properly indented. You still have syntax errors we were talking about earlier, like that missing colon between function argument's name and its type.

                            Read the error message, try to understand what it means and proceed to fix it. The easiest way would be by comparing the offending line with the same line in the tutorial. And remember, every character is important as it has a role within the language syntax.

                            Note that the engine will typically display only the first error it encounters. After you fix that error, it may show you the next error it found. So go fix them one-by-one as the engine reports them, until there are no more errors. At that point the exported properties should be displayed in the inspector.

                              xyz i found a few syntax errors:
                              Line 23:Expected closing ")" after function parameters.
                              Line 23:Expected ":" after function declaration.
                              Line 23:Expected end of statement after expression, found "Identifier" instead.
                              Line 24:Unexpected "Indent" in class body.
                              Line 28:Expected end of file.

                              im confused on the 2nd line 23 error that says to put a ":" after the function declaration, but i already putted it in as func move_ghost(next_position Vector2 delta float):

                              • xyz replied to this.

                                xyz just checked and i typed it the same except without the :'s in the paranthesis, gonna add it now

                                  SuperGibaLogan im now getting errors on 3 lines on this code:

                                  func on_position_reached():
                                  	 if current_scatter_index < 3:
                                  		current_scatter_index += 1
                                  	else:
                                  		 current_scatter_index = 0

                                  more specifically if current_scatter_index < 3:, else:, and current_scatter_index = 0

                                  • xyz replied to this.

                                    SuperGibaLogan Well the procedure is as I said. Fix the errors one by one by comparing what you typed to the code in the tutorial. Couldn't get any easier than that.

                                      SuperGibaLogan i checked the syntax error thingy and it says these lines marked in red are "Mixed use of tabs and spaces for indentation."

                                      • xyz replied to this.

                                        SuperGibaLogan i checked the syntax error thingy and it says these lines marked in red are "Mixed use of tabs and spaces for indentation."

                                        Well there you have it, loud and clear. You still have spaces in your indentation on those lines. Find them and delete them. It may be helpful to enable the drawing of space characters in the editor, similarly to how tabs are drawn. Go to Editor > Editor Settings > Text Editor > Appearance and enable Draw Spaces.

                                          xyz i removed one but im not sure about the current_scatter_index = 0, i think its like important to the code
                                          speaking of, when i remove that line, the navigation_area_2d.target_position = movement_targets.scatter_targets[current_scatter_index].position gets an error due to the current_scatter_index = 0 line being gone

                                          • xyz replied to this.