how to properly read or modify member variables of a node ?

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

It’s a very basic question but I don’t know if I’m doing things the right way.

To modify the name of a node for instance, I see that many people use the set_name() function but I don’t see this function in the docs and myNode.name = “newname” works too.

So, to access a member variable, do we have to use a set-get function or can we safely read or modify them directly ?

:bust_in_silhouette: Reply From: MrJJ

Hi
Well judging from the docs and most sample i have seen doing
get_node(“Label”).text = “HELLO!”
kind of access seems perfect legal.

:bust_in_silhouette: Reply From: Ertain

You can use setters or getters with your scripts, or you can access them directly. GDscript is pretty flexible like that. What you need to figure out is which method works best for your situation. If you find that using setters or getters works best for you (so that the member variables are protected), then go with that. If you require a more “hands-on” approach, and need to change or access the member variables directly, that’s fine, too.