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

2 Likes

my problem is

var isLeft = velocity.x < 0

sprite_2d.flip_h = isLeft

the second line is my problem… pls give me asolution

You didn’t say what your problem was, but I’m guessing that since a velocity of 0 is not less than 0, the character will always face right if the character isn’t moving. You can just check if the velocity is 0 and skip setting the flip value if it is.

I am also facing this problem and I am pretty sure you are here from coco code and BD, am I right? Well, I am also from there and learning Godot. But it’s daunting!

1 Like

did you find the solution?? if so i’d appreciate it if you can tell me the error