Global Array Based Player Choose Screen and Game Player Avatar

I am trying to create two arrays with the player avatar sprites in one, and the associated tower in another array. When the player clicks on the separate player name button he can see the player, his tower and its strengths and weaknesses as rendered through a text variable, finally there a play button which takes the player to the next level with player avatar and tower properties carried on i.,e a global variable.

Can anyone simplify the task for me, there’s the choose player screen UI!

Edit: I went on a bit but once I have an idea, I run with it. I also have no knowledge of your GDevelop experience. I can go deeper on any aspect. I’m kind of curious now and want to play with the concept. If I create a test project I can share it, if you’re interested in my concept. It requires some setup but the amount of flexibility is worth it.

I’m not sure what you’re asking. You could use a single structure of structures. Each structure could have as many children variables as needed. The first structure name would be the character’s name. You could access any of the other values through the name.


Chacters [VariableString (player)].Castle

It can be tedious to setup the variable. Once you have 1 structure setup with the children, you can copy and paste it and then change the values. The structure can contain as many children as needed and can include strings, numbers, boolean even more structures or arrays.

Unfortunately, you can only use **for each child ** with scene variables but you can create a scene copy of a global variable using JSON. You copy the global to scene, edit the scene and then replace the global with the scene copy if needed. You could put the events to copy the variable in an extension so you could make the copy with 1 action.

If you’re trying to access the variable through buttons then you use the button’s label text. If you use a scene variable or copy it to scene variable then you could use for each child to get the character names. This would allow for a more dynamic approach. You could filter the available characters by any of their child values. Example just add buttons for low level characters or type of character like say wizards. IDK what your game has. You could also use a boolean child variable called locked and lock some of the characters until unlocked. The variable could then be saved/loaded from storage.

I am in the halway mark between a newbie and intermediate. well in my project there are four player avatars to choose from, and each comes with a separate shooting tower. there are two things i did not understand in your answer:

does that mean i have to create a separate player structure?


are you talking about the extension JSON

Can you please elaborate on the steps i need to copy the global variable to the scene variable and still make them available for other scenes, if that is needed.

thanks in advance!

Think i got it now, four elements in the player strings structure, 4 castle elements in the tower structure and then we simply using the code you provided! am i right

That would depend. If you have a list of players and their castles then you could use a structure or an array. The main difference is arrays are index by sequential numbers while structures are just a list that you access by text variable names.

If all you need is player and tower name then you could use either a structure or array. You also probably wouldn’t need to copy the global variable to a local one if you’re only reading a few values.

A simple structure would be more flexible than an array since you can retrieve the values by name instead of number.

Let me throw something together. It’s easier for me than trying to explain. It also guarantees that I’m giving you the correct syntax.

Ok, though i am relatively new dev, i have an ambitious fun, strategic and educational game meant for older kids and pre-teens

1 Like

It sounds like an interesting project. A structure would be good because it would leave room for expansion.

Do you want me to share the project file?

Do you want me to share the project file?

No, I don’t have the time to dig too deep into a project. Let me just put together a generic example based on the concept or at least my understanding. Once you understand the concept then you can adapt it to fit.

ok, thanks a whole lot, :slight_smile:

It’s a basic setup using the 3 Stooges and 3 random countries.

Each button has a variable called “name”. At start change label text to the variable. You could use separate objects then put them into a group.

This would be the events to get the country based on the button label

try me:


I assumed your question was more involved than I believe it is. If I’m wrong, let me know. I’m going to put together a more advanced version. I’ll post it either later or tomorrow. You can use it or not. Either way, I hope you learn something.

1 Like

Again, thanks a lot, i’ll try it out later today!

1 Like

Here’s a screenshot of the global variable tree i made for feedback:

This is more advanced. It creates the buttons based on the structure and it uses multiple children. It also shows how to create a scene variable from a global using JSON. The json actions are under [other] [conversion]

try me:


can you show the variable sheets both global and scene

I’m done for the day. My second example might answer some questions. If not, there’s always tomorrow.

ok, no probs, sleep well, :sleeping:

1 Like