My game has multiple levels and unlocks next level when the previous level is completed. I am using a structure to load/save the status and other data related to each level. For example,
LevelStats.Level1.Unlocked
At the successful completion of a level, I simply add an action to unlock the next level:
To unlock level 2:
Set the boolean value of global variable of LevelStats.Level2.Unlocked to true.
For level 3:
Set the boolean value of global variable of LevelStats.Level3.Unlocked to true.
and so on.
I have multiple levels and this approach seems a bit manual and error prone. I would like to achieve it automatically. For instance, I would like to add something like this at the end of each level completion which will unlock the immediate next level.
Set the boolean value of global variable of LevelStats.{CurrentLevel}+1.Unlocked to true.
OR
Set the boolean value of global variable of LevelStats.{var}.Unlocked to true.
I’m curious, why not just use a global number variable to keep track of levels? You’ll need one anyway for this kind of dynamic structure access. The way to do this would be LevelStats[“Level”+GlobalVariableString(levelNum)].Unlocked, and toggle it to true.
Yes, I am using global variable to keep track of levels. My apologies for forgetting how to use dynamic values in structures: Variables - GDevelop documentation
Thanks for the inputs. I have modified the action as below and it worked
Make Global variable called LevelUnlocked and make it number variable
Make for each level Level variable and make it number variable
Making it so Level one have Level variable 1 Level two have 2 and so go on
On successful completion of level you ADD 1 to LevelUnlocked Variable
(for it to make sense that global variable needs to start with 1 not 0 so after completing level 1 it is 2 not 1)
Now you just make event that if LevelUnlocked variable = Level Variable then level is unlocked