Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help need an if satement that will differ which button is pressed!!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mitko1994




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Feltie




PostPosted: 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?
mitko1994




PostPosted: 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
crossley7




PostPosted: 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.
Tony




PostPosted: 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).
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
mitko1994




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: