[Solved] How do I name a variable using the value of another variable?

So I’m making a page system for a storage system I’m making, and I am trying to display a different animation on a sprite for each page.

What I’m trying to do is set a global structure variable for the current item (I’ll use “currentSprite” as an example) to another structure variable for the items in the player’s storage (I’ll use PlayerStorage.Item[num]). The code goes something like this:

“Change the global variable currentSprite to GlobalVariable(PlayerStorage.Item1)”

However I want to change the currentSprite to a different item based on the page number scene variable (pgNum) . So, if the variable pgNum was equal to 1, I’d want it to be PlayerStorage.Item1, but if pgNum was equal to 20, I’d want it to be PlayerStorage.Item20

I don’t know if this makes any sense, or if this is just a dumb question, but if you need me to elaborate I’ll try my best.

Sounds like you want to make PlayerStorage a Structure Variable. It’s like a dictionary and has key-value pairings.

Using your example variables, you can set currentSprite as GlobalVariableString(PlayerStorage[“Item” + VariableString(pgNum)]).

Yes, a tad complex, but all it’s doing is getting the string representation of pgNum, appending it to the string “Item”. It uses the resulting string as the key to the PlayerStorage structure and gets the string representation of the resulting value.


This solved my issue! Thanks so much :smiley: