What are the differences in using set and get vs just setting the variables straight

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

How is setting and getting things like postion different from setting and getting them like this

var my_pos = position
position = my_pos
:bust_in_silhouette: Reply From: Sween123

If you use the methods _get() or _set() without overwritting, then there’s no difference. They do the same thing.
However, it’s good to use _get() or _set() or even create your own get, set methods for your variables. The reason why we use these functions instead of directly putting an equal sign is that it helps to control the program. Having get, set, functions, or functions that overwirte the _get() or _set(), you can trigger events when the value is changed by putting more code inside them.
Let’s say you have a character scene, you have something like “HP” (Hit point), and you have a method set_HP(value). Although it’s fine to use HP = VALUE, but what if you want to update the text that should display the value of your character’s current HP value? If you use “set_HP(value)”, you can put other things inside this function, like the method for updating the HP text displayed in game.
Even if you want to trigger nothing when the value of a variable is changed, I still recommend using get, set, functions, because this way when later you want something to be triggered, you simply change the code inside these functions. It’s good for control.