Unexpected "Identifier" in class body error when using export in Godot 4.0.2

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Head150999

I’m currently working on a project in Godot 4.0.2 and I’m having trouble using the export keyword in my scripts. Every time I try to use it, I get an “Unexpected ‘Identifier’ in class body” error. I’m not sure what’s causing this error or how to fix it.

Here’s an example of the code I’m trying to use:

extends Node2D

export var growth_time = 10.0 var is_grown = false

I’ve tried searching for solutions online, but I haven’t found anything that has helped. Can anyone explain what’s causing this error and how to fix it? Additionally, is there anything I can do to prevent this error from occurring in the future?

1 Like
:bust_in_silhouette: Reply From: PolyBytes

Export variables have to be declared like this now in Godot 4:

@export var growthtime = 10.0

Also I would recommend assigning types to your export variables to ensure they are the type they need to be when you set them in the inspector and also it makes your code more efficient and resistant to bugs:

@export var growthtime: float = 10.0

GDScript Exports Documentation for Godot 4.0


my problem is

var isLeft = velocity.x < 0

sprite_2d.flip_h = isLeft

the second line is my problem… pls give me asolution