How to get a class property with a string?

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


I want to be able to something like that:

class ClassTest:
    var name

    func _init(name): = name

var temp ="Blue")

print(             <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 by using the string “name”, with something that could look like line <2>, and I don’t know how to do it.

:bust_in_silhouette: Reply From: wombatstampede

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)