I am working on a grid-based tactics game in which a player can choose a load out of 6 different creatures. imagine Pokemon meets Advanced Wars… ish.
Initially a set of global variables are defined in a structure based on a player’s selection. There are a lot of variables in the structure - Health, stamina, accuracy, speed, etc. All of which have a rolling total and a max value. All in all each creature structure has 22 variables.
During the battle the creature’s values are pulled from a global variable into a scene variable to define the active player and opponent combatant - there are 6 possible creatures for each combatant. I found creating a separate ‘active’ structure to be the best way to aggregate all future actions into one consolidated set of scene variables. IE - All future actions only have the reference the active creature rather than building out the logic each time.
Here’s my question/problem. It is arduous having to assign a value individually for all 22 variables in the structure when the global “Creature_X” structure is identical to the scene “Active_X” structure. Is it possible to copy the values from one structure to another over all at once?
I tried keeping it simple by having an action in which the value of the global structure copies into the value of the scene structure, but to no avail.
Any thoughts on an easy way to accomplish this so I don’t have to go variable by variable? Mind you, my entire approach here could be terrible! Open to any ideas.
I don’t know if this would help but I’ve seen people convert variables to JSON and then back to another variable. I tested this and it worked. I’m not sure if it fits your needs. There are expressions for scene, global and object variables.
Create a structure called person.
Store in temp.
Convert temp to person2
Great tip and this looks exactly like what I’m looking for! I’ll incorporate this into my rewrite once I dive deeper into working with JSON in GDevelop.
For now I’ve just chosen a hyper-consistent variable structure so all I have to do is change one value. This is a bit of a quirky work around, but to modify a set of variables from a structure in bulk I just copy and paste it into a clean scene event sheet. From there I use the search and replace feature to find a key word and replace it with my desired naming structure. Ex: I modified this ‘Active_Opponent_Creature’ structure to an ‘Active_Player_Creature’ with one search and replace instead of creating line by line.
Not going to lie. It’s an amateur move, but it works great for my purposes for now! Thought I would mention the janky process should anyone trying to avoid JSON come across this.
Isn’t it possible just to use
Then in the action:
Active_player_creature.name set to GlobalVariableString(Player_Creatures[“Creature”+ToString(variableX)].Name)
Go with what works. It can stink to have to completely rebuild variables or sometimes an entire project. You live and learn. Your strategy changes as your concept evolves and as your knowledge grows.
I can’t say I fully understand your concept. But it’s important to have organized variables/data. IDK what method would work best for your situation.
It might be easier to use a pointer or ID to the data instead of rearranging the data at runtime.
Agreed. You can use a structure of structures or an array of structures. I’m more used to arrays with parentheses than with brackets. We live. We learn. It’s sometimes difficult knowing the best way of helping with someone else’s project.