Topic was automatically imported from the old Question2Answer platform.
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?
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:
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!