Discord
Login
Community
DARK THEME

Savings in game

Is it possible to make saves there? maybe there is a library that can do it?


storage

storage.set( name, value ) 	
storage.get( name, value ) 	

If "Game over" means reloading by calling the "init" function in your game, then the record can be saved, for example, in a variable outside the function. In my example, after pressing the spacebar, the value of the "score" variable is stored in the "record" variable and then the "init" function is called. Thus, pressing the space bar means the end of the game and saving the record. After restarting the game, the record is saved, it is visible on the screen, you can also check it in the console.

record = 0
init = function()
  score = 0
end

update = function()
  score += 1
  if keyboard.press.SPACE then record = score init() end
end

draw = function()
  screen.clear()
  screen.drawText("Score: " + score, 0, 20, 20, "rgb(0,255,0)")
  screen.drawText("Record: " + record, 0, 0, 20, "rgb(255,85,0)")
end

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community