That would also totally work fine, but leads to the same number of events as my method above, and doesn’t really reduce complexity.
You always want to have your current game state structure be a different variable than your saves (to allow for reloading without having to go back to storage) and you want to avoid writing to or reading from storage frequently (to reduce situations where it is still being written to or loaded from when the player closes the game or a crash happens, because that can lead to corruption of the storage data or entire storage db).
With using a dynamic storage name you are still having to mix expressions and events, so there’s not any reduction of complexity. If it’s easier for shadow or you to follow, it’s totally fine. Just ensure you are keeping the above in mind.
1 Like
Oh my, it turns out I was greatly overcomplicating things, your solution works out fantastically, and I understand what I was doing wrong as well!
The CurrentSaveSlot was already moved outside prior, but I also tweaked the code, make the storage names more clear, and changed the slots to uppercase letters for convenience.
That being said though, I still have a few minor issues remaining:
-
Manually loading to a slot isn’t applying the values to the GameState. When I press L to load, the GameState doesn’t inherit the values, nor does the debugger change values.
-
Deleting save files doesn’t seem to work as intended. Ideally, I want to press X to wipe all the data in the current slot clean, poof, gone, reduced to atoms.
Unfortunately, when I restart the scene, all the data I just deleted is loaded right back in.
Even more strangely, the debugger clearly shows that the values have been reset, only to load them back in once the scene restarts??? What else to I need to delete the data permanently?
I can’t speak to your specific scenario, but as far as I know overwriting global variable A with another global variable B does not delete variables that exist in A but not in B, it just updates matching variables or create new ones that are missing. So you may be deleting your saves, but your GameState still has its existing variables.
I’d either make sure you have a “Defaults” global structure that you can overwrite GameState with at the beginning of the game (Opening scene or menu or whatever you prefer, incase you reset to menu after deleting a save), or add an action to delete the children of GameState as well.
Having a defaults structure for a new game is probably useful/important, though, incase your player ever loads a game, dies, then decides to just start from scratch.
1 Like
Thank you for the insight, I thought about it a little more, tinkered with it, and discovered that if the game is saved after deleting, the file STAYS deleted. Therefore, I made the game automatically save after the deletion of a file:
And yes, I’m aware that making default values are important for new games and such, but I appreciate you bringing it up for some foresight.
We’re in the home stretch now, there’s only one last issue that I just couldn’t wrap my head around. When I press L to manually load the game (As seen in the screenshot), the GameState values don’t change, not ingame, or in the debugger, so manual loading isn’t doing anything.
Basically, what I want is that when the game loads, the values from whatever slot I have selected would be applied to GameState, which doesn’t happen.
I’m using Saves[“Save”+CurrentSaveSlot] to try and load them in. Is this incorrect?
You have to use the GlobalVarToJSON() expression around it in order for it to work in the “Convert JSON String” action to work.
1 Like
Awesome, it’s up and fully running now! I’m surprised by how simple it all really is too!
I want to thank you kindly for being so patient with me, your information was immensely helpful. I’m very grateful you stuck this through with me until the end.
1 Like