Computer Science Canada

Help need an if satement that will differ which button is pressed!!

Author:  mitko1994 [ Sat Jun 04, 2011 3:59 pm ]
Post subject:  Help need an if satement that will differ which button is pressed!!

hi everyone, i'm making a game with true and false questions. I want to make a score counter however i'm not sure how to use an if statement to tell the computer if the answer is true and the true button is pressed add 1 to the counter variable. I use GUIprocessevent but i just dont know how to put it in an if statement so that it recognizes which button is pressed.I know it could be that i add the counter to the procedure called by the button however both true and false buttons lead to the same procedure(the next question) I use regular buttons not full.


thanks

Author:  Feltie [ Sat Jun 04, 2011 4:12 pm ]
Post subject:  RE:Help need an if satement that will differ which button is pressed!!

can you link the prgoram please?

Author:  mitko1994 [ Sun Jun 05, 2011 8:14 am ]
Post subject:  Re: Help need an if satement that will differ which button is pressed!!

var counter:int:=0
var f1,t1:int


procedure Question1
locate (2, 7)
put "Question1"
locate (8, 10)
put "The CN Tower is located in Toronto."
GUI.Show (t1)
GUI.Show (f1)
loop
exit when GUI.ProcessEvent
end loop
end Question1
procedure Question 2
locate (2, 7)
put "Question2"
locate (8, 10)
put "The capital city of Canada is Toronto."
%GUI.Show (t2)
%GUI.Show (f2)
%loop
% exit when GUI.ProcessEvent
%end loop
end Question2

t1 := GUI.CreateButton (170, 200, 0, "True", Question2)
f1 := GUI.CreateButton (250, 200, 0, "False", Question2)


Please tell me how to write an if statement so that if "t1" is pressed, it adds 1 to "counter" or at least tell me how to express the if statement so that it's boolean.

Thanks

Author:  crossley7 [ Sun Jun 05, 2011 9:22 am ]
Post subject:  RE:Help need an if satement that will differ which button is pressed!!

If t1 = GUI.GetEventWigetID then

elsif f1 = GUI.GetEventWidgetID then

try those and look at the turing documentation for GUI commands. I wrote a tron game earlier this year using it and completely self taught myself it using the documentation.

Author:  Tony [ Sun Jun 05, 2011 12:14 pm ]
Post subject:  Re: Help need an if satement that will differ which button is pressed!!

mitko1994 @ Sun Jun 05, 2011 8:14 am wrote:

...
loop
exit when GUI.ProcessEvent
end loop
end Question1

That loop will never exit (that is, until you call GUI.Quit, which will disable all of your buttons).

Author:  mitko1994 [ Sun Jun 05, 2011 4:57 pm ]
Post subject:  Re: Help need an if satement that will differ which button is pressed!!

Works perfectly! thanks crossley7 Wink Laughing


: