0 votes

The basic task stymies me. Put it in code:

class Foo:
    func _init():
        pass

    func some_func():
        var foo = Foo.new()

Will not work, because Foo identifier is not visible in some_func and in Foo class itself.

What have I missed? Or how to overcome the trouble?

First way I found for myself is to move class in singleton script, so one can access class identifier through singleton object. But I don't want to put my class into singleton for such a silly cause.

Second way is (probably) to create private function which returns Foo as load("Foo path"), but this trick is a dirty one.

in Engine by (26 points)

1 Answer

0 votes

Works for me.

class Foo:
    func _init():
        pass

    func some_func():
        var foo = Foo.new()
        pass

# Called when the node enters the scene tree for the first time.
func _ready():

    var f = Foo.new()
    f.some_func()
by (722 points)

Hm, very strange. I've tested this example, and I got Parser Error: Identifier not found: Foo in the line with Foo.new(). Using v3.0.6.stable.official.8314054

My apologies. I am using 3.1 alpha. I guess it was fixed?

Well, time will show. I'll wait for the stable release though, but thanks for the reply, probably, it is so :)

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.