using strings as node names.
-
im new to godot and ive figured out how to transfer my other coding experience over but one thing is racking my brain and i dont know if its because it can not be done or because im using the wrong nomenclature.
i have a dictionary that contains the names of buttons in the tree and an 1 or a 0 for if they should be toggled visible or not. the reason for this is that i would like to make a for loop that will show or ignore buttons on first load under _ready depending on they are set to 1 in the dictionary.
so basically all i want to do is a variant of this
$Button2.show()but i want the button node name "Button2" to come from the dictionary so something like
for item_name in dict_toggles:
temp = item_name
...
... #other code
if ...
$temp.show()in this case temp = "Button2" but as much as i have searched i can not find an answer or a "no you cant do this"
if anyone can help or point me to an example or just give me a no it cant be done that would be great thank you.
-
If i understand you correctly what you want is to use get_node instead of the $ shorthand, something like get_node("$/root/YourGame/Buttons/" + temp).show()
-
Amazing. That is where I was getting confused since when I looked up $ everything said it was get_node. The only thing I had to change from what you posted was remove the $/root/ then put the grid container name in and it worked perfect.
func _ready():
for item_name in dict_toggle:
var toggleArray = dict_toggle[item_name]
var toggle = toggleArray[0]
if toggle == 1:
get_node("GridContainer1/" + item_name).show()