Restarting my game after Saving Variables
Posted: Fri Sep 20, 2013 11:37 pm
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:
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:
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?
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
Code: Select all
love.filesystem.write("ShipX.lua", "return "..strmp.ship.x)
love.filesystem.write("ShipY.lua", "return "..strmp.ship.y)
Does anyone know why this is happening?