Hello world! Welcome to the twenty second Dev with Dave Game Progress Update! 🙂 It’s around 3pm on Friday afternoon as I write this, I still have to script record and edit the video and write all the social media posts (*sigh*) but I am hoping this update will at least be on the right day, if a little later than usual.
So, this update I have finished the Loading/Saving game data, and also spent some time removing duplicate code.
I’ve also taken some time out to get the Trello and the GDD updated.
Loading and saving game data
Having taken all the time available to me last time playing around with encryption for the save game file, this update I have managed to get the Loading and saving working properly.
The first time the game is run there is no save game data, so the game creates one using the default values. The LoadPlayerData() function then loads the data into an array and decrypts it. The decrypted data is then stored in the individual variables ready to be used in the game.
Saving the game data is pretty much the reverse. The data from the individual variables is stored in an array, then encrypted before being written to the file. If the file exists, it’s simply overwritten.
Both getting the loading and saving were quite easy to achieve in comparison to the next bit, which was updating the UI to reflect the data which had been loaded in.
Now, had I been smart, I would have considered this when I was writing the code which updates the store page info when the player makes a purchase and written it with a view of reusing it to update the display after loading the game data in as well.
It seems, however, I am not smart 🙁 as I did not do this at all! Which led to some serious rewriting and refactoring code.
A lot of the code used to update the UI display when purchasing an upgrade or boost was duplicated. It didn’t take too long to copy and paste the duplicated code into a function and make it more generic so it could be used for all instances where it was required.
I created four functions, one to update the upgrades store page after loading, one to update the boost store page, and two to update the individual items on either page. As you can see from the picture below, they didn’t quite work the first time round, lol.
The functions to update the store pages are called after the game data file is loaded in, and they both call the update store page item function for the relevant page, for each item on the page.
I also replaced the old code for updating the store page data when a purchase was made with the new function.
This refactoring has made the code some 750 lines shorter as well as making it much easier to read in places.
And that’s all for now
I still need to include data for the trophy progress in the game data file, but as there isn’t actually any trophy progress data currently I can’t do that just yet. It will have to wait until I have created at least one functioning trophy.
I’m not entirely sure what I’ll be doing for the next update. It’ll either be getting the IAP systems working or adding functionality to the Settings page. Maybe both if time allows?
Until next time 🙂