You need to use the
I/O library to save a file that contains the save information. I used this in
Skydiver 3.0. Here is the code:
Save highscore:
highscorefile = assert(io.open("highscores", "r"))
currentScore = highscorefile:read("*line")
highscorefile:close()
position_of_slash = string.find( currentScore, "/" )
score = tonumber( string.sub( currentScore, position_of_slash + 1, string.len( currentScore ) ) )
if level > score then
BGTopText:PrintXY( 1, 1, "Congratulations!" )
BGTopText:PrintXY( 1, 2, "You have the best score!" )
BGTopText:PrintXY( 1, 4, "Type your name please." )
require( "keyboard.inc.lua" )
name = keyboard( 20 )
writetoscorefile = name .. "/" .. level
highscoresfile = assert(io.open("highscores", "w"))
highscoresfile:write( writetoscorefile )
highscoresfile:close()
end
Load highscore:
function highScores()
Screen.Initialize( SCREEN_BOTTOM, BGBotText, BGBotBackground )
highscorefile = assert(io.open("highscores", "r"))
score = highscorefile:read("*line")
highscorefile:close()
position_of_slash = string.find( score, "/" )
name = string.sub( score, 1, position_of_slash - 1 )
score = string.sub( score, position_of_slash + 1, string.len( score ) )
-- Print out name and score
BGBotText:PrintXY( 1, 1, name .. " - " .. score .. " points" )
BGBotText:PrintXY( 1, 14, "Press A to go back." )
while Pads.A() == false do
end
styluswasinX = Stylus.X()
styluswasinY = Stylus.Y()
end