Array not visible inside a class function

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

So basically I have an array called units and inside a class function I’m trying to access that array. Looks like this:

var units = []

class Unit:
    func _init():
        print(units)

Except it always gives me an error: The identifier “units” isn’t declared in the current scope

:bust_in_silhouette: Reply From: patatra

Wasn’t it class_name name you confused with class?

:bust_in_silhouette: Reply From: jgodfrey

Assuming you want the units variable to be globally available within the Unit class, it needs to be defined inside the class. So, this:

class Unit:
    var units = []

    func _init():
        print(units)