how to use Object.set and Object.get ?

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

call this code in a node: why always output “my Null”
set(“my”, “abc”)
printt(“my”, get(“my”))

Does set only support built-in property?
Should I use set_meta for custom property?

alexzheng | 2018-08-28 01:37

:bust_in_silhouette: Reply From: kidscancode

That’s correct - set_meta() and get_meta() are used for attaching arbitrary data to an object.

:bust_in_silhouette: Reply From: volzhs

set(key, value) works for built-in or existing property.
if you want to use set() and get(), you need to define a variable for it.

var my

func _ready():
	set("my", "abc")
	printt("my", get("my"))

you can use set_meta and get_meta if it’s not predefined.