Book Image

Corona SDK Mobile Game Development: Beginner's Guide

By : Michelle M Fernandez
Book Image

Corona SDK Mobile Game Development: Beginner's Guide

By: Michelle M Fernandez

Overview of this book

Table of Contents (19 chapters)
Corona SDK Mobile Game Development Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – saving and loading the high score


When the Game Over screen displays, we will save and load the values of our final score and highest score. For this perform the following steps:

  1. 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.

  2. Add in two new variables, local highScoreText and local highScore where all the other initialized variables are located, near the top of the code:

    local highScoreText
    local highScore
  3. Introduce the saveValue() function after the preloaded 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...