Computer Science Canada My radiobutton quiz- With problems that need fixing! |
Author: | Yoda [ Sun Nov 28, 2004 4:46 pm ] |
Post subject: | My radiobutton quiz- With problems that need fixing! |
import GUI in "%oot/lib/GUI" View.Set ("graphics:550;300") setscreen ("graphics") var quitbutton : int var radio : array 1 .. 4 of int var score := 0 var response : boolean := false procedure QuitPressed if response = true then score := score + 1 put "correct!" else score := score - 1 put "Wrong!" end if delay (1000) GUI.Quit response := false end QuitPressed procedure RadioPressed %The score %var answers : array 0 .. 9 of int := init (2, 0, 2, 1, 2, 2, 1, 0, 2, 3) %These are the answers to the questions if radio (1) = GUI.GetEventWidgetID then response := false elsif radio (2) = GUI.GetEventWidgetID then response := false elsif radio (3) = GUI.GetEventWidgetID then response := true elsif radio (4) = GUI.GetEventWidgetID then response := false end if end RadioPressed procedure RadioPressed2 if radio (1) = GUI.GetEventWidgetID then response := true elsif radio (2) = GUI.GetEventWidgetID then response := false elsif radio (3) = GUI.GetEventWidgetID then response := false elsif radio (4) = GUI.GetEventWidgetID then response := false end if end RadioPressed2 procedure RadioPressed3 if radio (1) = GUI.GetEventWidgetID then response := false elsif radio (2) = GUI.GetEventWidgetID then response := true elsif radio (3) = GUI.GetEventWidgetID then response := false elsif radio (4) = GUI.GetEventWidgetID then response := false end if end RadioPressed3 put "Welcome to the Science Fiction Quiz of Doom!" delay (1000) put "" put "When you think you have the correct answer click on the radio button that" put "represents it, then, once you've done that, click the ANSWERED button." delay (2000) put "" put "May the force be with you and may Obi Wan Watch over you" put "" delay (2000) put "First question: What was William Gibson's first novel?" put "" delay (2000) radio (1) := GUI.CreateRadioButton (1, 75, "Pattern Recognition", 0, RadioPressed) radio (2) := GUI.CreateRadioButton (1, 100, "Virtual Light", radio (1), RadioPressed) radio (3) := GUI.CreateRadioButton (1, 125, "Neuromancer", radio (2), RadioPressed) radio (4) := GUI.CreateRadioButton (1, 150, "Dune", radio (3), RadioPressed) quitbutton := GUI.CreateButton (25, 200 - 1, 1, "ANSWERED", QuitPressed) loop exit when GUI.ProcessEvent end loop GUI.Dispose (radio (1)) GUI.Dispose (radio (2)) GUI.Dispose (radio (3)) GUI.Dispose (radio (4)) GUI.Dispose (quitbutton) cls put "Second question: Who is Luke's father?" put "" radio (1) := GUI.CreateRadioButton (1, 75, "Darth", 0, RadioPressed2) radio (2) := GUI.CreateRadioButton (1, 100, "Your Mom", radio (1), RadioPressed2) radio (3) := GUI.CreateRadioButton (1, 125, "Wintermute", radio (2), RadioPressed2) radio (4) := GUI.CreateRadioButton (1, 150, "Young buck", radio (3), RadioPressed2) quitbutton := GUI.CreateButton (25, 200, 1, "ANSWERED", QuitPressed) loop exit when GUI.ProcessEvent end loop GUI.Dispose (radio (1)) GUI.Dispose (radio (2)) GUI.Dispose (radio (3)) GUI.Dispose (radio (4)) GUI.Dispose (quitbutton) cls put "Third question: Who wrote the Martian chronicles?" put "" delay (1000) radio (1) := GUI.CreateRadioButton (1, 75, "You", 0, RadioPressed3) radio (2) := GUI.CreateRadioButton (1, 100, "Isaac Asamov", radio (1), RadioPressed3) radio (3) := GUI.CreateRadioButton (1, 125, "Ray Bradbury", radio (2), RadioPressed3) radio (4) := GUI.CreateRadioButton (1, 150, "C.S Lewis", radio (3), RadioPressed3) quitbutton := GUI.CreateButton (25, 200, 1, "ANSWERED", QuitPressed) loop exit when GUI.ProcessEvent end loop GUI.Dispose (radio (1)) GUI.Dispose (radio (2)) GUI.Dispose (radio (3)) GUI.Dispose (radio (4)) GUI.Dispose (quitbutton) cls ------------------------------------------------------------------------- Yar, run it, and you will see the problem. Question one runs nicely, but then #2 just zips by, and #3 is practically non-existent. If you have any suggestions, or solutions, to fix this problem, I shall forever be in your debt.[/b] |
Author: | Cervantes [ Sun Nov 28, 2004 5:12 pm ] | ||
Post subject: | |||
Yar! Yoda is speaking the language of the pirate? Arrrgh! Well, I don't know GUI, but I found that if you put a nice little GUI.ResetQuit after your event loop:
it works nicely. Your GUI.ProcessEvent is always returning true, ever since the first time you called GUI.Quit. So you need to reset the GUI.Quit. |
: |