How do I make a Radio button quiz?
Author |
Message |
Yoda
|
Posted: Fri Nov 12, 2004 12:23 pm Post subject: 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 <<<35>>>,
<<<"Radio Button 1">>>, 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 <<<15>>>, maxy 35,
<<<"Radio Button A (Shortcut: 'a')">>>, 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 (<<< "text" >>>). Tell me what you think should solve this problem of mine. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
bass_maniac
|
Posted: Mon Nov 15, 2004 8:47 pm Post subject: (No subject) |
|
|
You should add import GUI at the beginning. Like this,
code: | import GUI
View.Set ("graphics:350;80")
(etc....)
|
|
|
|
|
|
|
Yoda
|
Posted: Tue Nov 16, 2004 10:55 am Post subject: (No subject) |
|
|
[code]import GUI
View.Set ("graphics:550;300")
%The score counter
var count: int
var radio : array 1 .. 4 of int
% The radio button IDs.
procedure RadioPressed
Text.Locate (1, 1)
put "Time for the " ..
for i : 1 .. 4
if radio (i) = GUI.GetEventWidgetID then
put i ..
end if
end for
put " Selected "
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 [/code]
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
|
Posted: Tue Nov 16, 2004 5:53 pm Post subject: (No subject) |
|
|
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.
code: | 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
|
Posted: Wed Nov 17, 2004 10:25 am Post subject: (No subject) |
|
|
[code]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
put "Welcome to the Science Fiction Quiz of Doom!"
delay (500)
put ""
put "When you think you have the correct answer click on the radio buttonthat represents it"
delay (1000)
put ""
put "May the force be with you and may Obi Wan Watch over you"
put ""
delay (1000)
put "First question: What was William Gibson's first novel?"
put ""
delay (1000)
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)
loop
exit when GUI.ProcessEvent
end loop[/code]
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. |
|
|
|
|
|
|
|