0 votes

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

Godot version v3.4
in Engine by (12 points)

2 Answers

0 votes

Wasn't it class_name name you confused with class?

by (83 points)
0 votes

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)
by (16,852 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.