Question already said almost everything. I mean I want something like this in GDScript // same with setget behavior
native.variable = something
print(native.variable) # print: "something else" because setter function in NativeScript add "else"
Question already said almost everything. I mean I want something like this in GDScript // same with setget behavior
native.variable = something
print(native.variable) # print: "something else" because setter function in NativeScript add "else"
In the Godot C++ source code, getters and setters are just functions that get used. For example, if you want to get the global transform of a Spatial node, in C++ you need to use Transform trans = node.get_global_transform()
, unlike in GDScript where you can use var trans = node.global_transform
(though under the hood, the GDScript code does the same thing).
You'll probably need to make setter and getter functions, and then use them directly. So in your example, it would probably need to be something like the following (C++ like pseudo code):
native.set_variable(something);
print (native.variable)
// example setter function
native::set_variable(variable p_argument) {
variable = p_argument; // normal setter
variable = "something else"; // override in the setter
}
That said, there may be a way to define getter and setters in C++ so you can just modify the variable, I just do not know what they would be right off. I know in the Godot source code, getter and setter functions are used directly, with direct variable modification being used when necessary.
Oh, that sad. It will force me to modify code many places to implement native class correctly.