Need help with saving

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Red Pig
Prole
Posts: 3
Joined: Wed Jan 08, 2020 10:00 am

Need help with saving

Post 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
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Need help with saving

Post 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.
Red Pig
Prole
Posts: 3
Joined: Wed Jan 08, 2020 10:00 am

Re: Need help with saving

Post by Red Pig »

So shouldn't I be able to create the players hitbox with the saved player coordinates?
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Need help with saving

Post 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).
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests