Topic was automatically imported from the old Question2Answer platform.
Asked By
Godot_Starter
I have five Sprites. The names are like this: Sprite1, Sprite2, … . And I have a variable. And I want to hide the Sprite which name end on the number of the variable. I think about somerhing like this:
You can use the $ reference the Child Node MySprite with $MySprite or the Other Child Node with $MySprite2.
or you could use the get_node function to get the child node. The pathing is relative so you could do it like this:
var mySprite = get_node("MySprite") # to get the Child Node
var mySprite2 = get_node("MySprite2") # to get the Other Child Node
var myGrandChild = get_node("MySprite/MyOtherNode") # to get the Grand Child Node
Now that you can do that, you can use string concatenation or interpolation to get the one you want:
var mySprite2 = get_node("MySprite" + "2") # to get the Child Node 2
var mySprite3 = get_node("MySprite" + "3") # to get the Other Child Node 3
or
var mySprite2 = get_node("MySprite{number}".format({"number":"2")) # to get the Child Node 2