Original date: December 10, 2021
So, we now have a pause feature, and a pause screen with menu. That was easy.
We also have a save and load feature. That was not easy.
I originally intended to allow the player to save mid-mission. Well, nope. The thing is, Godot doesn’t actually come with a save feature, you have to script it yourself. That means I have to exactly tell it what to save. Every variable, every current value, and write that into a JSON file. Loading is the same in reverse, read the contents of a JSON file and populate variables with the values from that file.
If I wanted to load mid-mission, I’d not only have to store the current position and orientation of the player (which will be difficult to restore as the physics engine won’t let me move the player by setting the coordinates), but also which enemies are dead and which alive, which powerups were collected, which doors were open or closed, which switches were in which position and so on. Yeah, no.
Of course I can’t just store the state of the current level in the JSON, because a level is a “scene” and a scene is a “node” (that’s what Godot calls any game object). And guess what cannot be stored in a JSON? Precisely: nodes.
So, the player can save between missions and load from the title screen. Which is actually exactly how it was in the original game. That way I only have to store a couple of global variables. Well… and which weapons the player already has. Which I write in an array/list. And what is an array? A node…
At least it’s a small list, I just have to store each entry of the list in the JSON and recreate the list on load. So, yes, it works. Whew.