When the player does something good or bad, you may as well let their score reflect their performance. This chapter will teach you how to add or subtract from the players current score as well as set the maximum score value that is displayed in the control window.
Handling the players score is actually relatively easy.
AddToScore(150 5)
The first parameter being passed is a unique flag number, and the second value is the value to be added to the score. Have you ever played a game where you can do the same action over and over again getting the same points infinitely. The first value, the unique test value, prevents that from happening. As part of the AddToScore procedure, this test value is passed through another procedure Btest automatically. It checks to see if the flag has been set against that number and if it hasn't, then the value gets passed to Bset which then sets the flag to TRUE and finally the points are awarded. If the same action is repeated, because the flag has already been set to TRUE, the points will not continue to pile up. Of course, all of this happens behind the scenes so it isn't something that you will need to worry about, all you need to know is that every change of the score using AddToScore will need a unique flag, or identifier, and a value to add to the current score.
Now, when it comes to the first parameter, or the unique flag as described above, rather than have a bunch of arbitrary numbers floating around your game that you are going to have to try and keep track of, the first thing we are going to want to do is add a new section to our game.sh file. This will allow us to give a meaningful name to these unique flag numbers. So lets go ahead and create the section as well as add in the first couple of test values to demonstrate getting and losing points. These flags can be used for much more than just points and as the tutorials here near completion, you will see them used in a number of different ways, but regardless of using the value to test for getting points or some other purpose... each flag will need a unique number. You can use any number you want, starting at 1, you have to skip over 0 as it will always return True for whatever reason.
Just an FYI, currently the number of flags available is determined in the global variables of the main script. In order to add more Btest Flags, you would only need to change the 14 to something larger. Straight out of the box, you have 224 flag variables available.
gFlags[14] // Start of bit set. Room for 14x16 = 224 flags.
Now then, to give the flags meaningful names, you will need to open the game.sh file and define a few values. You can define these values with any name that you choose, I just tried to give them something meaningful to make it easier to read when it is actually used in a room's script.
//***********************************************
// Btest Flag List
//***********************************************
(define POINT_GETTESTITEM 1)
(define POINT_FELLINHOLE 2)
Now that we have a couple of flag variable names defined, we can use it in the syntax introduced above.
Add to the players score
AddToScore(POINT_GETTESTITEM 5) // positive number
Remove points from the players score
AddToScore(POINT_FELLINHOLE -102) // negative number
That pretty much covers getting and losing points. Refer to the chapter on
Complex Interactions for ideas on where to put these in order to trigger the point scoring based on specific actions taken by the player.
Maximum Score
As for changing the maximum score available in the game. You will need to open up the main script, 000, and scroll down to the Template public class of Game. in the init method, you should see this line.
= gMaxScore 5000
Simply change that 5000 to whatever value you want... like say 250. One good habit to get into, always, always, compile all scripts after you have made any changes in the main script. Depending on what and where you make changes, your game will often crash if you haven't compiled all of the scripts, or at the very least leave you with some very unexpected results.
And there it is, changing the player's score and setting the maximum game score.
Going Further
If you are interested in adding to the player's score without all of the hassle of needing to check a flag, then might I suggest checking out the
Changing the Player's Score Revisited chapter under Modifications to learn how.