16 May 2017

a narrative rpg | development blog
Previous post
Next post
16 May 2017 || Saving and Loading

Hooray, a great addition to the game has been finished this week!It is... saving and loading the game! With multiple save slots even:

I have to say, I'm still a little surprised that I actually got it all working. And very suspicious, whenever something just works after I've worked on it for hours I can't help but feel like there's some monstrous bug hiding in the depths just waiting to rear its head and tear down everything. I'm keeping an eye on you, game!

So, pretty happy to have this part working. I remember way back when I first looked up a tutorial on how to create save files for games and load the data back in, and I was fairly terrified by how complicated some of it looked back then. Now it wasn't that bad, a lot of little parts that had to be carefully put together, but none of the parts themselves were hard to do.

Of course there's still some stuff that needs to be added to the save as the game becomes more finished and there's more things to save (and the looks of the save slots aren't final of course, they're just filled with text for debugging help), but for now the saving and loading includes:

-Relevant character stats: Levels, excess exp etc.
-Inventory items and their amounts
-Money amount
-Story progress list (keeps track of scenes you've visited, story scenes completed etc.)
-Current scene
-Player position and which direction you were facing

Btw, if you're like me and had never before taken a peek at what save files might actually look like (one that's not encrypted into nonsense, that is) and are curious about it, here's one from the game in its current state:

{"saveCharacters":[{"Name":"Emil","Level":1,"CurrExp":0,"CurrHp":11,"IsInParty":false},{"Name":"Mikkel","Level":12,"CurrExp":0,"CurrHp":365,"IsInParty":true},{"Name":"Sigrun","Level":8,"CurrExp":0,"CurrHp":69,"IsInParty":true},{"Name":"Reynir","Level":1,"CurrExp":0,"CurrHp":2,"IsInParty":true},],"progressList":["hasNot_doneAnythingCool","hasNot_battled","01-exit_module","02-southern_ice_fields1"],"invItemSlugs":["a_rock","dead_rat","adrenaline_shot","bandages","first_aid_kit","xp_booster"],"invItemAmounts":[19,2,3,1,3,15],"moneyAmount":50,"sceneName":"02-southern_ice_fields1","PlayerPosX":193.36000061035157,"PlayerPosY":29.189647674560548, "LastMoveDirX":0.0,"LastMoveDirY":-1.0,"playHours":0.0,"playMinutes":0.0,"playSeconds":9.0,"textSpeed":0}

Pretty neat, huh? All of those pieces have to first be gathered from all around different parts of the game code when saving, arranged into a neat little wrapper, then read back in from the file and carefully put back in where they belong. Got to make sure the team won't accidentally have all their levels switched around!

That's it for this time. I think next time I'll try to finish another important technical part of the game, resolution settings, since it's kind of needed for testing purposes. I really want to start working on the battle system, but I'm trying to do these less exciting major parts first. That way I hopefully won't work myself into a bag where everything ends up breaking and has to be rebuilt once I finally do get around to them.