ARS361
Interactive Digital Multimedia
Instructor: B. Lattanzi
rev.2.8.04
----EXAMPLE OF CASE STATEMENT FOR TEXT
--THIS USE OF THE CASE STATEMENT CAN BE USED TO CREATE AN "ELIZA"-LIKE DIALOG BETWEEN THE VIEWER AND THE COMPUTER.
-- This example also includes use of custom handler ("parseReply") and a repeat statement to quickly move the program through the viewer-typed words.
property answerSprite, questionMember, answerMember
on beginSprite me
answerSprite = sprite(me.spriteNum)
questionMember = member "question"
questionMember.text = "what do you see?"
answerMember = member "reply" -- this member must be a field type of cast member
answerMem.text = ""
end
on keyUp me
if (the key = RETURN) then
put "enter"
me.parseReply()
end if
end
on endSprite me
questionMember.text = ""
answerMember.text = ""
end
on parseReply me
repeat with i = 1 to answerMember.text.word.count
case (answerMember.text.word[i]) of
"birds": questionMember.text = "tell me more"
answerMember.text = ""
exit repeat
"alligators": questionMember.text = "why?"
answerMember.text = ""
exit repeat
otherwise
questionMember.text = "I don't understand. Try again."
end case
end repeat
end
|