Counting Scores

Back to the
How To index

About SC Simple Quiz
Get Started
A Field For Questions
Adding Answers
Scripting the quiz
Setting Up the Quiz
Counting Scores
Further Developments

.
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 myGlobalName
We 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 wrongAnswer
All 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, 
--but we could have built the whole answer string in one go. --get put the string into the special varable it --line 2 of gScores = a varable, the correct answer --& an ampersand joins strings together --" out of " a literal string --(the number of this cd) the number of this cd will be the number of questions answered. --line 1 of gScores a varable, the number of tries --CR is understood by SuperCard as a return character
if it is "quit" then quit else go cd 1 end if end rightAnswer

New Project Menu

Next we are going to looks at some possible improvments.

PREVIOUS NEXT