0 votes

Hi, my code looks something like this:

func _ready():
    var test = SecondClass.new(4)
    test.method_example()

class FirstClass:
    var a
    func _init(a):
        a=a

class SecondClass:
    extends FirstClass
    func _init(a).(a):
        pass

    func method_example():
        print(str(a))

However I have not fo und a way to access a from SecondClass, is this even possible?

in Engine by (65 points)

1 Answer

+2 votes
Best answer

Hi,

the problem here is that you pass a parameter named a and have a instance field named a. Prefix your variable with self to point to the instance variable (or change the parameter name). Then it will work.

class FirstClass:
var a
func _init(a):
    self.a=a
by (306 points)
selected by

Yeah, that made it work, thanks!

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 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 webmaster@godotengine.org with your username.