Looking for a save/load function
-
Looking for a Save/load function for my game,
I know there's other posts covering this but i'm failing to incorporate it into my game.
Is it possible to save Whole Arrays
example:
playerstore=[.Pgold = 0,keys = 0 ,.life = 3,.x = player.x,.y = player.y ]
I have others for Npc's but focusing on this one array for now.
Currently i have the array repeated for my game over screen so it gets reset, but wanting to carry it over game runs so people don't have to spend half the day playing it through and allowing me to open up the scope of the game to a fullish game experience.
i did spend most of last sunday stabbing away at it but felt pretty lost, I understand it needs to write save /seek and load but just a little lost. -
If you are using pianofire's persistent code, you can just do it like this:
To load stuff in your init function:
store = [] if loadStore() then playerStore.PGold = getValue("PGold") playerStore.keys = getValue("keys") playerStore.life = getValue("life") playerStore.x = getValue("x") playerStore.y = getValue("y") endif
Note that the loadStore() function returns false if there was no persistent data already saved, so you will then need to populate playerStore with some default values. Also note that store needs to be a global variable.
To save stuff whenever necessary:
setValue("PGold", playerStore.PGold, "int") setValue("keys", playerStore.keys, "int") setValue("life", playerStore.life, "int") setValue("x", playerStore.x, "int") setValue("y", playerStore.y, "int") saveStore()
-
@vinicity cheers I'l have another bash at it, always overwhelming trying something new but i feel i can handle that
as long as i can get one working then the rest will follow -
I do it in my car race game one value at a time, you can have a look.
-
Defo use pianofire’s code for this. It makes it so easy!
-
@Ithendall cheers, nice to have a game as reference plus i'v not managed to play it yet been busy in a coding frenzy haha
-
Well, it is still in progress, not finished :)
-
For lists of stuff like that, I do (for example)
For x = 1 to 10 loop SetValue(”myList[”+str(x)+”]”,myList[x],”int”) repeat``` ..or something like that. See how it works?
-
Nevermind i think i'v figured it :)
-
I was just giving another example for if you have an array of structs, or a highscore list or something. It wasn’t aimed at your question there. Good you got it sorted though :)
-
@toxibunny yeah i got that, i'm fine with this for now though thanks man