[Solved]Loading variables isn't working with filesystem
Posted: Mon Jul 21, 2014 8:27 pm
I'm trying to save a highscore variable using love.filesystem and when I do this, I can save the file and the information inside it. I just can't figure out how to load the data properly?
This is the error I get:
This gets written into the save.lua file my game creates:
This function is in love.load()
I then have this function called when I click the 'highscores' button on my main menu
I'm not really too sure what the problem seems to be.
This is the error I get:
Code: Select all
saving.lua:6: Syntax error: save.lua:1: '<name>' expected near '0'
Code: Select all
highscore: 0
Code: Select all
function save()
saveisthere = love.filesystem.exists("save.lua")
if not saveisthere then
savefile = love.filesystem.newFile("save.lua")
love.filesystem.newFile("save.lua")
print("File Creation Successful!")
highscore = 0
print("Data Cleared.")
savefile:open("w")
savefile:write("highscore: " ..highscore)
savefile:close()
print("New Data Saved.")
end
if saving then
savefile = love.filesystem.newFile("save.lua")
savefile:open("w")
savefile:write("highscore: " ..highscore)
savefile:close()
print("New Data Saved.")
end
end
Code: Select all
function load()
saveisthere = love.filesystem.exists("save.lua")
if saveisthere then
love.filesystem.load("save.lua")()
end
if not saveisthere then
print("No Save File Detected.")
end
end