O'Reilly logo

Monkey Game Development by Michael Hartlef

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — loading and saving the high-score list

To load and save the state of a game, and so the high-score list, just copy some code from the game CometCrusher.

  1. Copy the following code from the LoadHighScore method of Chapter 4, Game #3, CometCrusher.
    Method LoadHighScore:Int ()
    Local state:String = LoadState()
    If state Then
    eng.scoreList.LoadFromString(state)
    Endif
    Return 0
    End
    
  2. Again, copy the following code from the SaveHighScore method from Chapter 4, Game #3, CometCrusher.
    Method SaveHighScore:Int ()
    Local hs:String = g.eng.scoreList.SaveToString()
    SaveState(hs)
    Return 0
    End
    

What just happened?

By reusing these two methods, you have saved yourself some valuable time for the future development of this game. It seems small, but when you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required