Handling the Player's Score

What's a good adventure game without a score?

Scores are an essential part of any game. This chapter will teach you how to handle them. Scores are very easy to handle with SCI. The score bar and score variables are all set up in the main script.

First you need to open the main script. Open the game and the Game Explorer will load. Click on the scripts tab and the list of scripts in your game will appear. Scroll down the list until you see the "Main" script. Double click on it, and the script editor will open it.

Setting Up The Score
The score revolves around two global variables: gScore and gMaxScore. If you scroll down the list of global variables (main's local variable block), you will find the score variables.

Code: [Select]
  gScore =  0 ; the game score
  gMaxScore =  0 ; the maximum game score
  gOldScore ; previous score

These are the score variables. The gScore variable contains the current score. The gScore variable contains the game's maximum score. Finally, when you add to the player's score, the previous score is stored in gOldScore.

To set the game's maximum score, simply change gMaxScore's value from 0 to whatever your game's score will be.

Updating the Score
Updating the score is incredibly simple. You just make a call to the game class' changeScore() method.

Code: [Select]
  (gGame changeScore: 3) ; Will add 3 to the players current score
  (gGame changeScore: 8) ; Will add 8 to the players current score
  (gGame changeScore: 167) ; Will add 167 to the players current score

Customizing the Score Bar
You naturally won't want your game's score bar to say "Template Quest". This being the case, you can change it easily by scrolling down to the StatusCode instance somewhere about line 340...

Code: [Select]
(instance statusCode  of Code
  (method (doit param1)
    (Format param1 { Score: %d of %-3d______________________Template Game_} gScore gMaxScore)

Simply change the text "Template Game" to whatever name you have chosen for your game and play with the spacing a bit to get everything lined up just the way you want. The ___ can't be seen, as the border of the score bar will be drawn over it.