Restarting my game after Saving Variables

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
Bransonn
Prole
Posts: 8
Joined: Wed Apr 24, 2013 6:13 pm

Restarting my game after Saving Variables

Post 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?
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Restarting my game after Saving Variables

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

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 3 guests