IceQB wrote:If I correctly understand action of filesystem.newFile, it must make new file so if i for test write
Learning to program step 1: Learn English. Sorry, but your English is so bad that I can barely understand what you are trying to say. And of course that means that you probably cannot really understand our answers either. You could try finding a programming forum where people use your native language, however, sooner or later you will need English.
Code: Select all
var = {}
var.score = 0
var.highscore = 0
No bug here.
Code: Select all
function love.load()
love.filesystem.load("highscore.lua")
end
You have to load AND run the Lua file, you only load it.
Code: Select all
function love.update(dt)
var.score = seconds
What "seconds"? You have never defined a variable called "seconds" and thus seconds is "nil" i.e. this line actually deletes "var.score"!
And thus it crashes here. "var.score" no longer exists. And the whole approach is wrong anyway. Only update the highscore before you save it.
Code: Select all
function love.draw()
local statistics = ("highscore%d"):format(var.highscore)
gfx.print(statistics, 100, 0 )
local statistics = ("score%d"):format(var.score)
gfx.print(statistics, 100, 10 )
end
"gfx" is another undefined variable.
Here is the whole thing fixed. It still doesn't do anything sensible, though. Using "dt" as a score value makes no sense.
Code: Select all
var = {}
var.score = 0
var.highscore = 0
gfx = love.graphics
function love.load()
savedData = love.filesystem.load("highscore.lua")
if savedData then savedData() end
end
function love.update(dt)
var.score = dt * 1000
end
function love.draw()
local statistics = ("highscore%d"):format(var.highscore)
gfx.print(statistics, 100, 0 )
local statistics = ("score%d"):format(var.score)
gfx.print(statistics, 100, 10 )
end
function love.quit()
if var.score > var.highscore then
file = love.filesystem.newFile("highscore.lua", "w")
file:write("var.highscore = " .. var.score)
file:close()
end
end