NOVICE QUESTION: Best way to get a property?

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

Hello everyone, i’m a godot novice and just started learning gdscript :slight_smile:
There seems to be multiple ways to access an objects/class/nodes? name.

say i got a node and i wanted to get either a name or a custom property:


With custom properties it’s just these two i know of:

health = 10;


What is the prefered method and why?

:bust_in_silhouette: Reply From: Calinou is the preferred syntax – built-in properties also use this syntax since Godot 3.0. However, get() and set() can be useful to get/set properties with dynamic names (that is, the property’s name itself is variable).

There’s one other case where you must use get()/set(): when a property name contains special characters such as / (which may be the case of a few built-in properties).

Thanks :slight_smile: Great answer!

threepwood | 2019-04-07 23:35

1 Like