I'm curious what the best approach would be to save the current state of my game. The lua scripts contain the gamestate, but also some gameplay related info that doesn't need to be stored as part of a savegame.
Should I split my lua scripts into a 'saveable state' part and pure gameplay stuff like dialogs?
What would you recommend for a store/restore mechanic? I could serialize the info to JSON and just store it as a textfile, and on load set all the values in the lua state I suppose?
A alternative could be to have C++ load all relevant info from the Lua state, and store it in some format..but that seems more work than just serializing some lua tables.
As an example, here is one object inside a level that contains both gameplay logic (onOpen
) and state info (opened
):
skull = {
opened = false,
rect = { 64, 29, 14, 16 },
sprite = "entrance_door_skull",
dialogs = {
look = "It's the skull of some creature. Its meaning seems quite clear: death lurks inside.",
},
onOpen = function(self, scene)
if not self.opened then
addMove("skull", 1000, 0, -12, function ()
SceneGameEntrance.actionItems.skullKey.isVisible = true
end)
addDialog("As if by magic, the skull rises.")
self.opened = true
else
addDialog("It is already open.")
end
end
}