godot-extended-libraries / godot-next

Godot Node Extensions - Basic Node Extensions for Godot Engine
MIT License
964 stars 61 forks source link

Use the setter to change the path #48

Closed Smiley32 closed 4 years ago

Smiley32 commented 4 years ago

As it's within the class, setget doesn't work, and target won't be set, so we should use the setter explicitly

willnationsdev commented 4 years ago

Since we already have a setget defined for the property though, would it be better to use self.target_path = ... instead of set_target_path(...)? That way, if the setter is ever changed to something else, you don't then also have to update it a secondary location where the assignment was meant to happen. self.<property> = will simulate an external access to manually trigger the setter on the property.

Smiley32 commented 4 years ago

Of course it's better to use the setget if we can. But as mentioned in the documentation, self.target_path = ... won't call the setter since the instruction is inside the class

Whenever the value of variable is modified by an external source (i.e. not from local usage in the class), the setter function (setterfunc above) will be called.

https://docs.godotengine.org/en/3.1/getting_started/scripting/gdscript/gdscript_basics.html#setters-getters

willnationsdev commented 4 years ago

Yes, but prefixing the property access with self. actually forces a simulation of an external access. :-) I invite you to give it a try. Unless something changed from 3.1 to 3.2...

Smiley32 commented 4 years ago

Oh, I'm sorry. You're totally right. So yes, it would be better to use that instead of directly the setter I think.

willnationsdev commented 4 years ago

Not really a big deal which one we use ultimately. I'm gonna merge.