
-----------------------------------
Yoda
Fri Nov 12, 2004 12:23 pm

How do I make a Radio button quiz?
-----------------------------------
View.Set ("graphics:350;80")

var radio : array 1 .. 6 of int        
% The radio button IDs.

procedure RadioPressed
    Text.Locate (1, 1)
    put "Radio Button " ..
    for i : 1 .. 6
        if radio (i) = GUI.GetEventWidgetID then
            put i ..
        end if
    end for
    put " Selected"
end RadioPressed

radio (1) := GUI.CreateRadioButton (15, maxy ,
    , 0, RadioPressed)
radio (2) := GUI.CreateRadioButton (1, 1, "Radio Button 2",
    radio (1), RadioPressed)
radio (3) := GUI.CreateRadioButton (1, 1, "Radio Button 3",
    radio (2), RadioPressed)
radio (4) := GUI.CreateRadioButtonFull (maxx , maxy 35,
    , 0, RadioPressed,
    GUI.RIGHT, 'a')
radio (5) := GUI.CreateRadioButtonFull (1, 1,
    "Radio Button B (Shortcut: 'b')", radio (4), RadioPressed,
    GUI.RIGHT, 'b')
radio (6) := GUI.CreateRadioButtonFull (1, 1,
    "Radio Button C (Shortcut: 'c')", radio (5), RadioPressed,
    GUI.RIGHT, 'c')

loop
    exit when GUI.ProcessEvent
end loop

-----

This doesn't work, and I have put the mistakes in tags (>). Tell me what you think should solve this problem of mine.

-----------------------------------
bass_maniac
Mon Nov 15, 2004 8:47 pm


-----------------------------------
You should add import GUI at the beginning. Like this,

import GUI
View.Set ("graphics:350;80")
(etc....)


-----------------------------------
Yoda
Tue Nov 16, 2004 10:55 am


-----------------------------------


Ok, so, I have that down, but now I need a system to keep score of how many times to person taking the quiz gets a question correct. How would I do this with the program above?

-----------------------------------
bass_maniac
Tue Nov 16, 2004 5:53 pm


-----------------------------------
This doesn't work and I don't know why. Basically you set the number of questions with the answers array and set what button is the correct answer. So the first time they click a button it checks to see if the button clicked matches the correct one. If it does then the score is increased by one and a message is displayed. The questionNum is also increased by one. 

I repeat that this doesn't work, but maybe it'll give you an idea, or maybe you can figure out why it doesn't.

import GUI
View.Set ("graphics:550;300")

%The score counter
var count : int
% The radio button IDs.
var radio : array 1 .. 4 of int
%The score
var answers : array 1 .. 10 of int := init (3, 3, 2, 4, 2, 3, 1, 4, 2, 4) %These are the answers to the questions
                 %Change ^ to however many questions you have
var score := 0
var questionNum := 1

procedure RadioPressed
        if answers (questionNum) = GUI.GetEventWidgetID then %If the button clicked = the correct button then
            locate (1, 1)
            put "You got it right!"
            score += 1
        else
            locate (1, 1)
            put "You got it wrong!"
        end if
        questionNum += 1
end RadioPressed

radio (1) := GUI.CreateRadioButton (1, 100, "", 0, RadioPressed)
radio (2) := GUI.CreateRadioButton (1, 125, "", radio (1), RadioPressed)
radio (3) := GUI.CreateRadioButton (1, 150, "", radio (2), RadioPressed)
radio (4) := GUI.CreateRadioButton (1, 175, "", radio (3), RadioPressed)

loop
    exit when GUI.ProcessEvent
end loop


-----------------------------------
Yoda
Wed Nov 17, 2004 10:25 am


-----------------------------------


Hmmm....

Well, that's what I've changed it to, not much of a difference, just words and garbage. Giving the buttons a value seems to be really difficult, and I honestly can't figure out why. If someone can see the solution to this problem, please, please, please post it.
