Page 1 of 1

Restarting my game after Saving Variables

Posted: Fri Sep 20, 2013 11:37 pm
by Bransonn
I've been working on a way for my game to save the x and y coordinates of my player in a state. I do this so if I leave the state/game and come back, the player is right where I left 'em.

So the game loads in this order: stateOne --> stateTwo --> stateThree

I save the x and y coordinates into files called ShipY.lua, and ShipX.lua, both of which return a number.

I do this by:

Code: Select all

        

        local file_shipx = love.filesystem.newFile("ShipX.lua")
	local file_shipy = love.filesystem.newFile("ShipY.lua")

	starmapone.ship.save_shipX = love.filesystem.load("ShipX.lua")()
	starmapone.ship.save_shipY = love.filesystem.load("ShipY.lua")()

	starmapone.ship.x = starmapone.ship.save_shipX
	starmapone.ship.y = starmapone.ship.save_shipY


And it loads it just fine. Working wonderfully. When I move the character, I have the game save the players coordinates. I do this by:

Code: Select all

                                love.filesystem.write("ShipX.lua", "return "..strmp.ship.x)
				love.filesystem.write("ShipY.lua", "return "..strmp.ship.y)
Which saves the file. This way I can always close the program and be exactly where I left off. The problem I'm having though, is that every time it saves, it goes back to stateOne. I thought it might have something to do with modifying a file in use, so I made the x and y regular numbers and had the game save to a different file that wasn't in use. Still goes back to stateOne.

Does anyone know why this is happening?

Re: Restarting my game after Saving Variables

Posted: Sat Sep 21, 2013 7:54 am
by Plu
How would the game know to jump straight to state 3 instead of state 1? Do you save that somewhere as well?

(Also it helps to include a .love file of your game)