Identifier "state" not declared in the current scope for no reason

Godot Version

Godot 4.2


Hello, i was programming the statemachine for character in 2d platform fighting game but godot 4 detected an error which said “Identifier ‘state’ not declared in the current scope”, I don’t know what that means and I don’t even know what to do? or it’s because of my phone which im using to create the game or this update have some meltfuctions, here the script i wrote:

extends Node

@export var Id = 1

func _ready():

func state_logic(delta):

func get_transition(delta):

func enter_state(new_state, old_state):

func exit_state(old_state, new_state):

func state_includes(state_array):
for each_state in state_array:
if state == each_state:
return true
return false

And here the problem:

if state == each_state:

If you know what that means, tell me how do I declare

you will need to declare the state in a variable first, right now no one declared a variable or property or method named state

below the @export

var state

And where is csharp?

An identifier not declared means you typed out the name of a variable that was not defined beforehand with a var statement. The current scope bit tells your that the block of code in which you used it (a function, a for loop) is where it can’t find the declaration. In your case, you never declared state using var state at any point. The program doesn’t know what state means and what it should contain because you never told it. You could either declare state to be a variable that holds something or replace it with the thing you want to compare to each_state. It depends on what you are trying to make this code do.