0 votes

Hi,

I want to be able to something like that:

class ClassTest:
    var name

    func _init(name):
        ClassTest.name = name

var temp = ClassTest.new("Blue")

print(temp.name)             <1>
print(temp._get("name"))     <2>

The line marked with a <1> works fine, because it's how a class works, but I want to get temp.name by using the string "name", with something that could look like line <2>, and I don't know how to do it.

in Engine by (86 points)

1 Answer

0 votes

Use `temp.get("name")' .

`_get()' is a virtual function which can be overriden in a class to use (at least as I understand) as custom property get function. (similar to setget functions)

by (3,358 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.