• Godot HelpGDScript
  • [GODOT 4.1] a line of code says its an error even though it actually isnt

hi, im making a game and im watching a tutorial to program it, i did exactly what the tutorial was doing but i have a problem

godot said a piece of the code is wrong even though in the tutorial, it doesent have any errors, im using the same godot version the tutorial was using, so how do i solve this?

this is the code, the "navigation_agent_2d.target_position = movement_targets.scatter_targets[current_scatter_index].position" part is the one where it has an error:

extends Area2D

var current_scatter_index = 0

@export var speed = 90
@export var movement_targets: Resource
@export var tile_map = TileMap

@onready var navigation_agent_2d = $NavigationAgent2D


func _ready():
	navigation_agent_2d.path_desired_distance = 4.0
	navigation_agent_2d.target_desired_distance = 4.0
	navigation_agent_2d.target_reached.connect(on_position_reached)
	
	call_deferred("setup")

func _process(delta):
	move_ghost(navigation_agent_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() * speed * delta
	position += new_velocity

func setup():
	navigation_agent_2d.set_navigation_map(tile_map.get_navigation_map(0))
	NavigationServer2D.agent_set_map(navigation_agent_2d.get_rid(), tile_map.get_navigation_map(0))


func scatter():
	navigation_agent_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
		
navigation_agent_2d.target_position = movement_targets.scatter_targets[current_scatter_index].position

just incase you need to see the tutorial to solve the problem, heres the link:

    SuperGibaLogan You forgot to post the error message.
    The last line in your posted code is not indented properly.

    oh yeah
    heres the error message:
    "Error at (43, 1): Unexpected "Identifier" in class body."

    • xyz replied to this.

      xyz so i tried to remove some things one by one in that piece of code but it didnt work

      • xyz replied to this.

        SuperGibaLogan @export var tile_map = TileMap

        here's your problem

        it should be @export var tile_map : TileMap

        • xyz replied to this.

          Jesusemora No, that's the future problem 🙂. The code compilation failed at parsing stage due to bad indentation, which is evident from the error message. It didn't even get to checking for expression errors.