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.
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.
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.
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.
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.
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]