I have an object named “Star”. I manually place 3 of the Stars around the level.
Once the player is in collision with the star, the boolean value of variable “PickedUp” turns to true.
My question is, how do I save the boolean value of each instance of the Star.
The reason why I need this is, if the player manages to get only 2 out of 3 stars, and decides to try the level sometimes later again, I would like for the Stars that had their boolean “PickedUp” changed to true, not to be shown upon repeating the level.
I apologize, but saving is somewhat difficult for me to understand.
A solution is to add a unique identifier on each star for each level. Easiest is to add a number object variable to the star with a value of 1, 2 or 3.
Then use a global structure to store the state of each star on each level upon level completion. Something like
(although it’s using values, the boolean is still intact - true is the same as 1, and false the same as 0)
When you start a level, read the states and assign it to each star. If the star’s state isn’t in the structure, GDevelop will add it automatically and default it to false (or 0, it’s the same thing).
I think it is very close to working. Right now what is happening is that once the star has been picked up, it doesn’t show up if I come back to that level. However if I close the preview and start it, they appear again.
Thank you very much for answering my problems. I’ve tried many things but I just can’t seem to get to save the actual values if the star has been picked up or not.
Do the write to storage after the repeat event, not during the repeat event. The repeat events populates the structure, and you save it once in a separate event afterwards
Don’t parse jsonPickedUp into the object variable PickedUp. jsonPickeUp is a string representation of the structure that was saved.
Parse jsonPickedUp into the global variable StarState
.
And then just link it in each scene you want to save the star states. This saves you having to remember to copy and paste into every game scene. In each game scene, right click on "Add a new event" to link it: