Scripting the Quiz

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

.
This is what we have:

Card Screenshot

Now we can put in some scripts to make the quiz work.
At the moment, nothing happenswhen we click the buttons. We are going to add scripts to the buttons to make something happen.

To edit the script of a button, we can select it with the pointer tool, and choose Script from the Edit popup on the Property Inspector, or go through the Object Info dialog, via the Edit menu.
It is probably quicker to use the Browse tool and hold the option and shift key down while the mouse is over an object.

Card Screenshot
We are going to use 2 very simple scripts in side the buttons:
In a wrong answer Button:

on mouseUp
	 WrongAnswer
end mouseUp
In the Button with the right answer:
on mouseUp
	 RightAnswer
end mouseUp
now if we click on a button, we get a dialog telling us SuperCard cannot understand WrongAnswer (or RightAnswer)

So we need to add scripts to handle this. A good place for thes scripts is the background shared by all the cards. No matter how many question (cards) we have they will all share the same background.
Hold the control key down and hit b to edit the script of the background.
the script editor opens, enter this script:

on wrongAnswer
	answer "Wrong! Try again."
end wrongAnswer
Now try clicking on a wrong answer button:

Card Screenshot

Here is a script for the right answer:

on rightAnswer 
	answer "Right, Well Done."
end rightAnswer
We want to go to the next question(card) so we can do this:
on rightAnswer 
	answer "Right, Well Done."
	go next card
end rightAnswer
The problem with this is that it dosen't let us stop, when we get to the last card, we go back to the first, so:
on rightAnswer 
	answer "Right, Well Done."
	
	--comments start with 2 - in superCard
	-- these are ignored when the script runs, they are not red in SC

	--work out if it is the last card if not go to the next card
	--if it is the last question offer to quit or start again
	if the number of cards > the number of this cd then go next
	else answer "Game Over." with "Quit" or "Start Again"
	if it is "quit" then quit
	else go cd 1
end rightAnswer

Beleve it or not we have a functioning quiz the next page lets you know how to set it up.next.

PREVIOUS NEXT