|
Back to the How To index
About SC Simple Quiz
|
. |
|
Here is a simple way of counting a score. We will use a global varaible. A global varaible is a varaible that can be accessed by different scripts at different times You need to declare a global before you use it eg: global myGlobalNameWe are going to count the number of trys in line 1 of our var and the number correct in line 2. We could have used separate globals, but this is to my mind simpler. Here are the changes first to the wrongAnswer handler in the background script(control B to edit it) on wrongAnswer global gScores answer "Wrong! Try again." add 1 to line 1 of gscores end wrongAnswerAll we did was declare the global gScores and add 1 to it Here is the rightAnswer handler: on rightAnswer global gScores answer "Right, Well Done." --first we add 1 to the count of questions answered --and 1 to the count of the right answers add 1 to line 1 of gscores add 1 to line 2 of gScores if the number of cards > the number of this cd then go next else get line 2 of gScores &" out of "&(the number of this cd)& " in "&line 1 of gScores &" tries."&CR answer it & "Game Over." with "Quit" or "Start Again" --Here instead of just answer game over, we built a string to tell the user their score. --I did this in 2 lines of script to make it easier to read on the web, |
| PREVIOUS | NEXT |