I'm making a game where a player will click a button where a number is randomly generated, this number then correlates to a card that is supposed to be unlocked. How I have my game set up is that the rng button will send a signal to the storage scene which then matches the signal to a certain number. So far everything has been fine and dandy in that sense.
However my main problem now is figuring out how to access all 32-cards without using get_node 32 times or using 32 signals. Specifically I want to know how would I reference all 32 cards to modify their properties such as their labels, images, etc
Why do you need get_node 32 times? Do you want to modify all cards or only the matched one? If you only need to modify the matched one, then you will only do get_node once and then assign that to a variable so you can further manipulate it.
I want to specifically modify the card that matches with the signal, however I don’t want to do “get_node” for each card and that’s why I was wondering if there was a better solution.
A couple things may address this, depending on how you are doing this now (a snippet of the signal you are sending or the receiving code may be helpful to confirm).
You can send a value with a signal when the button is pressed, which corresponds to the random number that is generated
signal number_selected(random_number: int)
func select_random_number():
var rand = randi_range(1,32)
number_selected.emit(rand)
Then the receiving class should have a list of all the nodes, and grab the node in the list that matches the passed number.
On initialization (_ready function) you can put all the nodes into an array or dictionary. You essentially do have to call get_node once per card (if they are already existing as nodes in a list) in order to make them available in the storage scene, but you can do it one time and then save the results, and access them later.
–
If the scenes aren’t yet existing as nodes in the place you want them to appear, and you are instantiating instances of them, and all the files are in the same location in a folder in your file tree, you can programmatically load all the nodes in a specific folder and put them into an array.
This may also be a good use case for Resources. Create a new type of resource with all the info a card needs, like image and label etc. Then there should be a single scene for the cards.
When you need a card, you can instantiate a copy of the card scene and then pull the resource and apply the details from the resource into the card. Then you can make changes to that instantiated scene. In that case you would list all the resources in your array
–
If you let me know if any of these address your issue / give more context and some snippets of your code and I can provide an example / clarify more.