My game has dungeon scenes that contain door objects that use the boolean object variable “Unlocked” to determine when they are open and when they are closed. I want it so that every time a door is “Unlocked,” the variable is saved to a storage so that if the player reloads the scene, like by exiting the dungeon scene and then entering it again later, the door stays Unlocked instead of being in its locked state again.
My issue is, I’m unsure exactly how to load variables for this specific object. I can save them to storage as text just fine, but it seems I can’t load the variables directly into the objects. Furthermore, I don’t want the variable to load for all instances of the object at the same time, only each unique instance. Otherwise, every single door on the scene would either be locked or unlocked at the same time. Some similar topics I’ve seen mention structures, but I don’t yet quite understand how to use those well.
If you give each door a unique number id - you can use an array of booleans for their state and save that to storage. You can put this array variable in a structure of everything that you need to save to storage.
Array variable DoorUnlocked[door.id]
so when it has been retrieved from storage- set ‘count’ to zero and repeat number of children DoorUnlocked times
I’ve made a new array variable with some boolean variable children, but I don’t understand how to save and load with this type of variable. Could you please explain?
Hi you need a scene or global variable that’s an array. You’ve got an object variable there but you need to give each door a unique number using an object number variable…either on the editor or inside a repeat event at the beginning of the scene. The array will relate to these unique numbers…stating whether they have been unlocked. Zero has posted details on how to save to storage above. Ansel’s idea might be good but I’ve not used save state yet …sadly…so I don’t know enough about it.
Every time a door is unlocked, its ID is added to the scene’s Small_Door array variable.
I’m still not really sure how exactly to save and load the boolean variables themselves though. @petlimpet sorry if you already explained it in your first reply, but I’m having trouble understanding what you mean. Do I also need to add each unique door object’s boolean variable along with their ID to the scene array, and if so, how?
that repeat event - that’s what to do when you read the array really or ‘for every child in an array’
to number them you want to ‘repeat for each door’
how many doors are there? You’ll be renumbering their ID each time in a repeat event…which could be a problem- if you’re changing the scene as people are playing the game.
as they’re unlocked change the array so change SmallDoor[Small locked door.ID] to true. Then when its saved to storage it should update the array. When you’ve loaded the save file you need to read that array and any true children …select the door with the ID that equals the index (once they’ve been numbered). …and change the object var to true