Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / LOAD/SAVE Game state

Author
Message
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 10th Mar 2018 13:32
Does anyone know of a way to implement a load/save game state for use as a save game feature?
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 10th Mar 2018 18:15
Yes. Any other questions?






To be slightly more detailed - you'll need a struct/type that keeps track of gamestate. Then you'll need a function to write this to disk in some structured manner. Best option is to serialize the struct/type into a JSON string, and simply dump this to disk. If worried about people editing their save-data, you can take the JSON string and put it into a memblock before saving.

To load back, you need an option at the start of the game to load the save game. This reads back the JSON (or if using a memblock, reads the memblock and then extract the JSON from it), transfer the stored values to the gamestate struct/type, and starts the game from that gamestate.
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 10th Mar 2018 18:39
Are you suggesting that there be a single struct/type variable/array to keep track of all program data separately?
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 10th Mar 2018 19:33 Edited at: 10th Mar 2018 19:33
How you structure your app and keep track of game-state is up to you. There is no 'one-size-fits-all' solution, as each app is unique, and all us programmers got our own preferences and styles. You just need figure out what works best for you and your app from a practical point of view.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 14th Mar 2018 17:18
Like Dybing says, each game/programmer will have different methods. Planning out what you need to save before you write the game might be helpful. Make a list of variables that you want to save, including stuff like time passed, points gained, health levels, sprite locations, quest progress, etc. If you can fit everything into an array or memblock, saving the info will be easy.

Login to post a reply

Server time is: 2024-11-27 14:33:10
Your offset time is: 2024-11-27 14:33:10