When the Game Over screen displays, we're going to save and load the values of our final score and highest score.
Open up your
main.lua
file that we created for Egg Drop. We'll continue using the same file and add in more code with the new alterations to the game.Add in two new variables,
local highScoreText
andlocal highScore
where all the other initialised variables are located near the top of the code.local highScoreText local highScore
Introduce the
saveValue()
function after the pre-loaded sound files.local saveValue = function( strFilename, strValue ) -- will save specified value to specified file local theFile = strFilename local theValue = strValue local path = system.pathForFile( theFile, system.DocumentsDirectory ) -- io.open opens a file at path. returns nil if no file found local file = io.open( path, "w+" ) if file then -- write game score to the text file file:write( theValue...