home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / dirwin / data.z / ANIMWIZ.DIR / 00007_Script_RadioButton < prev    next >
Text File  |  1996-03-15  |  2KB  |  88 lines

  1. -- RadioButton Script
  2.  
  3. property ichCurrent  -- keeps track of the channel number of the user's current choice
  4. property ichStart  -- the channel number of the first answer
  5. property inChannels  -- the number of possible answers (channels)
  6. property iRightAnswer  -- the correct answer (if there is one, or zero if not specified)
  7.  
  8. on birth me, startCh, nChannels, rightAnswer, defaultAnswer
  9.   set ichStart = startCh
  10.   set inChannels = nChannels
  11.   repeat with ch = ichStart to (ichStart + inChannels - 1)
  12.     puppetSprite ch, TRUE
  13.   end repeat
  14.   
  15.   -- If no right answer was specified, set iRightAnswer to 0, so we can check later
  16.   if voidP(rightAnswer) then
  17.     set iRightAnswer = 0
  18.   else
  19.     set iRightAnswer = rightAnswer
  20.   end if
  21.   
  22.   -- Check for a default value specification
  23.   if voidP(defaultAnswer) then
  24.     set ichCurrent = 0
  25.   else
  26.     if defaultAnswer = 0 then
  27.       set ichCurrent = 0
  28.     else
  29.       set ichCurrent = ichStart + defaultAnswer - 1
  30.       set the castNum of sprite ichCurrent = the castNum of sprite ichCurrent + 1
  31.       updateStage
  32.     end if
  33.   end if
  34.   
  35.   return me
  36. end birth
  37.  
  38.  
  39. on mHit me
  40.   set newCh = the clickOn
  41.   
  42.   if ichCurrent <> 0 then
  43.     if newCh = ichCurrent then
  44.       return  -- clicked on the already down button
  45.     end if
  46.     -- Change the current Down button to the Up version
  47.     -- Since this is the Down button, subtract one to get to the Up button
  48.     set the castnum of sprite ichCurrent = (the castnum of sprite ichCurrent) - 1
  49.   end if
  50.   
  51.   set ichCurrent = newCh
  52.   -- Since this is the Up button, add one to get to the Down button
  53.   set the castNum of sprite ichCurrent = (the castNum of sprite ichCurrent) + 1
  54.   updateStage
  55.   
  56. end mHit
  57.  
  58.  
  59. -- Return the value of the button hit (0 means no answer)
  60. on mGetChosenAnswer me
  61.   if ichCurrent = 0 then
  62.     return 0
  63.   else
  64.     return (ichCurrent - ichStart + 1)
  65.   end if
  66. end mGetChosenAnswer
  67.  
  68.  
  69. on mEvaluate me
  70.   if iRightAnswer = 0 then
  71.     alert("Attempting to evaluate, but a correct was not given at initialization")
  72.     return FALSE
  73.   end if
  74.   
  75.   set currentAnswer = mGetChosenAnswer(me)
  76.   if currentAnswer = iRightAnswer then
  77.     return TRUE
  78.   else
  79.     return FALSE
  80.   end if
  81. end mEvaluate
  82.  
  83.  
  84. on  mCleanUp me
  85.   repeat with ch = ichStart to (ichStart + inChannels)
  86.     puppetSprite ch, FALSE
  87.   end repeat    
  88. end mCleanup