About using variables to read global variables

Hello, I am a new user who has been using gdevelop for less than a month.
I’m making a Pokémon-like game. I made some arrays to store those characters’ data, such as attack and defense.At the same time, I created a sprite on the screen with a different character in each frame.

I want to read the number of picture frames in the array through the ID of different characters, so that the character can be displayed on the screen.

I’ve tried using variables to read the children of the array, for example
VariableString(flagship) = “musume”+ Tostring(Variable(flagship))+“[1]”
frame numble = GlobalVariable(VariableString(flagship))

but it doesn’t work.

Now I try to use variables to replace the numbers in brackets in the array, but it doesn’t work too.

I can only come here to ask how to solve it.

Sorry, English is not my first language, it may be difficult for you to understand what I am saying, I will put my code below.

If kanmusume1 is an array, then you can only access it’s children using a numeric index, and not a string as you have done. So it should be GlobalVariable(kanmusume1[Variable(flagship)]).

However, that will only append the value to the array., and the way you try to set the animation in the next line won’t work; you’re trying to set the animation frame to the array, which won’t work.

I think what you want is to use a structure variable. It’s like a dictionary in standard programming languages, in that it has key-value pairings. The key is a string, and the value is any GDevelop variable type. It appears to be the kind of variable you need.

Thanks, it took me a day to finally figure out what I was doing wrong. I didn’t do anything wrong by using variables instead of numbers for global variables. I just made a mistake with the sprite frame number, it starts from 0.

I thought it started from 1, lmao.