HyperCard Scripts for Generic Quiz
NOTE: The character "¬" corresponds to the continuation mark for a long
script line.
Stack Scripts
--------------------------------
-- quiz card scripts
--------------------------------
on setUpQuiz
-- initialize variables for quiz section
global qList,qPointer,qMax,qScore,reviewList,qTries
-- qList: item list of the question cards
-- qPointer: item number of current question
-- qMax: total number of questions
-- reviewList: names of missed questions
-- qTries: number of quiz attempts
put the number of cards in bg "quiz" into qMax
put scrambleItems(qMax) into qList
put 0 into qPointer
put 0 into qScore
add 1 to qTries
put empty into reviewList
end setUpQuiz
on nextQuiz
-- advance to next quiz question
-- qPointer: current quiz question
-- qMax: total number of quiz questions
-- qList: item list of quiz questions
global qPointer,qMax,qList
if qPointer=qMax then
-- if this was last quiz, go to finish screen
go card "done quiz"
else
-- go to quiz card
add 1 to qPointer
go card (item qPointer of qList) of bg quiz
end if
end nextQuiz
function scrambleItems nItems
-- randomly scrambles list of numbers from 1 to nItems
repeat with i=1 to nItems
put i & "," after theList
end repeat
repeat for nItems times
-- random by swapping items in list
put random (nItems) into firstOne
put random (nItems) into secondOne
put item firstOne of theList into temp
put item secondOne of theList into item firstOne of theList
put temp into item secondOne of theList
end repeat
return theList
end scrambleItems
--------------------------------
-- result card scripts
--------------------------------
on displayResults
-- calculate quiz scores
global qMax,qScore,reviewList,theUser
-- VARIABLES
-- qMax: total number of questions
-- qScore: number correct on first answer
-- reviewList list of missed questions by topic name
-- precentage needed to pass
put 80 into passingScore
lock screen
hide bg button "self-test"
show bg button "topics"
-- calculate score
put (qScore / qMax * 100) div 1 into userScore
put "You scored" && qScore && "correct on the first try"¬
&& "out of a total of" && qMax && "questions, or" ¬
&& userScore & "%." & return & return into cd field "results"
if userScore >= passingScore then
-- user passed minimum
set the style of card field "results" to rectangle
show card button "certificate"
hide card button "redo"
put "Since you exceeded " & passingScore & "%, you have passed the requirements"¬
&& "for this section of the Orient Express."¬
& return & return & return¬
& "CONGRATULATIONS," && word 1 of theUser && "!" & return & return¬
& "Click on the arrow button to receive your Orient Express certificate."¬
after cd field "results"
set the textStyle of line 6 of card field "results" to bold
set the textSize of line 6 of card field "results" to 24
set the textStyle of word 4 of line 8 of card field "results" to bold
else
-- user did not pass minimum
hide card button "certificate"
show card button "redo"
put "Since you scored less than " & passingScore & "%, you should review the information"¬
&& "for this unit of the Orient Express. You may now:" & return¬
& " 1. redo the self check (click on the redo button); or" & return¬
& " 2. review the topics listed below (click on the topics button)" & return¬
& "------------------------------------------" & return¬
& "TOPICS to REVIEW" & return¬
& "(You may wish to write down the topics you missed)" & return & return¬
& reviewList after cd field "results"
set the textStyle of line 7 of card field results to BOLD
set the textStyle of word 9 of line 4 of cd fld results to BOLD
set the textStyle of word 10 of line 5 of cd fld results to BOLD
if the number of lines in reviewList > 3 then
set the style of card field "results" to scrolling
else
set the style of card field "results" to rectangle
end if
end if
unlock screen
end displayResults
on fillCertificate
-- prepare score sheet
global qScore,qMax,reviewList,theUser,qTries
lock screen
menuSet "self-test",FALSE
menuSet "topics",TRUE
if qScore = qMax then
-- perfect score
put " " into missedQuestions
else
-- list missed questions
put "-----------------------------" & RETURN ¬
& " Missed Questions" & RETURN & reviewList into missedQuestions
end if
-- fill data fields
put theUser into card field "username"
put the long date & ";" && the time into card field "theDate"
put qScore && "correct out of" && qMax &"," ¬
&& (qScore/qMax * 100) div 1 & "%" & " N=" && qTries¬
& RETURN & missedQuestions into card field "userScore"
unlock screen
select before line 1 of card field "userID"
end fillCertificate
on printCertificate
-- print info to last selected printer
print "Authoring Quiz" & return & return¬
& short name of this stack & return¬
& "<-> ---- Certificate of Completion ---- <->" & return & return¬
& card field "userName" & RETURN¬
& card field "userID" & RETURN¬
& card field "theDate" & RETURN¬
& card field "userScore"
end printCertificate
Background Scripts
These scripts are available to every card that uses the quiz background
on openCard
-- set up quiz card
global qPointer,qMax,firstTry
-- VARIABLES:
--
-- qPointer: current quiz number
-- qMax: total number of questions
-- firstTry: =0 if user has not tried at least once
-- update card counter
put qPointer && "of" && qMax into bg field "count"
set cursor to watch
lock screen
-- show answer fields
ansVis TRUE
-- reset try flag
put 0 into firstTry
-- randomly sort the list of answers
put scrambleItems(4) into fList
-- reset the location of answer fields
repeat with i=1 to 4
get "ans" && item i of fList
set the topLeft of bg field it to 10,(70 + i * 54)
set the topLeft of bg button it to 2,(64 + i* 54)
end repeat
-- hide NEXT button until user tries once
hide bg btn "next"
unlock screen
end openCard
on closeCard
-- clean up card
global reviewList
hideHilite
hideFb
ansVis false
put empty into bg field count
hide bg field "help"
end closeCard
on ansVis state
-- toggles visibility of answer fields
repeat with i=1 to 4
set the visible of bg field ("ans" && i) to state
end repeat
end ansVis
on checkAnswer
-- compare users response and show correct feedback
global firstTry,qScore,reviewList
-- exit if user clicked on last response
if the hilite of bg button (short name of the target) then exit checkAnswer
-- hilite the button
hideHilite
set the hilite of bg button (short name of the target) to true
lock screen
-- hide all feedback fields
hideFB
-- get name of selected answer and show feeback
get word 2 of the short name of the target
show bg field ("fb" && it)
-- score if this was first try
if firstTry = 0 then
-- enable NEXT button
show bg btn "next"
-- check answer with name of current card
if it=char 3 of the short name of this card then
add 1 to qScore
else
put bg field "topic" & return after reviewList
end if
put 1 into firstTry
end if
unlock screen with wipe left
end checkAnswer
on hideHilite
-- turn off all button hilites and reset left of answer fields
lock screen
repeat with i=1 to 4
set the hilite of bg button ("ans" && i) to FALSE
-- set the left of bg field ("ans" && i) to 18
end repeat
unlock screen
end hideHilite
on hideFB
-- hide all feedback fields
repeat with i=1 to 4
hide field ("fb" && i)
end repeat
end hideFB
on setAnswer
-- flash the text of the field back field and reset the correct answer
set the name of this card to "qz" & word 2 of the short name of the target
repeat 4 times
select line 1 to 5 of the target
wait 15 ticks
select empty
end repeat
end setAnswer