Page 1 of 1

Need help with saving

Posted: Mon Feb 10, 2020 1:33 am
by Red Pig
I'm using windfield and this is how I make the players hitbox at startup

Code: Select all

player.body = world1:newRectangleCollider(player.x, player.y, 35, 33)
Anyway I want save the player's coordinates in player.x and player.y with this when the game exits so that when it opens it up player.body will be at these

Code: Select all

player.x, player.y = player.body:getX(), player.body:getY()
I've tried using bitser to do this but I don't really understand how to and I can't get it to work
So could someone tell me what I should be doing

Re: Need help with saving

Posted: Mon Feb 10, 2020 7:27 am
by raidho36
When you load a game save you re-create the gamestate from scratch, the same way as you do when you just load a game. The difference is that regular game load uses default values, and save game load uses saved values.

Re: Need help with saving

Posted: Mon Feb 10, 2020 9:19 am
by Red Pig
So shouldn't I be able to create the players hitbox with the saved player coordinates?

Re: Need help with saving

Posted: Mon Feb 10, 2020 10:01 am
by raidho36
Yes you should. You shouldn't try to read from uninitalized blank hitboxes though.

Programming ain't magic. There's literally nothing that happens without your explicit instruction to do so, in other words, you must issue specific instructions for anything to happen. So pay great mind to what instructions you're issuing, don't expect things to just "somehow work out".

If that's not the answer you wanted, that's probably because you didn't ask the right question. Did you want a specific advice on how to implement savegame functionality? You write all of your savedata to a string, and then dump it into a savefile. To load a game to you do the reverse - load a string from a savefile, and read all of your savedata from that string (read values and write them to relevant game objects).