Hi
I'm looking for a tutorial to create a A highscore with writing and reading a file
Thank you
Bernard
How to create a highscore? please
Re: How to create a highscore? please
I once implemented it using "classic" to create the Score Object.
Follow Sheepolution's tutorials to learn more about "classic".
This example also uses "ser" to save and load the score from the file.
Feel free to ask questions if you don't understand something.
When the bullet hits the enemy:
You should do the last check at the end of the game anyway.
In the menu:
Follow Sheepolution's tutorials to learn more about "classic".
This example also uses "ser" to save and load the score from the file.
Feel free to ask questions if you don't understand something.
Code: Select all
Score = Object:extend()
-- Set the X and Y position of the score label
function Score:new(x, y)
self.x = wWidth - 100
self.y = 20
end
function Score:update(dt)
end
function Score:draw()
love.graphics.setColor(255, 255, 255)
love.graphics.print("Score: " .. scor, self.x, self.y)
end
function Score:saveMaxScore()
local data = {}-- Make a table to store variables in.
data.maxScor = scor
-- Save the table to the "savegame.txt" file:
love.filesystem.write("savegame.txt", serialize(data))
end
function Score:loadMaxScore()
if not love.filesystem.exists("savegame.txt") then
maxScor = 0
score:saveMaxScore()
end
-- Load the data table:
local data = love.filesystem.load("savegame.txt")()
-- Copy the variables out of the table:
maxScor = data.maxScor
return maxScor
end
Code: Select all
scor = scor + 1
if scor > maxScor then
score:saveMaxScore()
end
In the menu:
Code: Select all
maxScor = score:loadMaxScore()
love.graphics.print("Best Score: " .. maxScor, wWidth - 150, wHeight - 30)
Re: How to create a highscore? please
Thank You very much
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot], SiENcE and 1 guest