Computer Science Canada Clickable buttons |
Author: | sammi [ Sun Oct 16, 2011 1:59 pm ] | ||
Post subject: | Clickable buttons | ||
What is it you are trying to achieve? <Im trying to make my yes/no buttons clickable> What is the problem you are having? <they wont click> Describe what you have tried to solve this problem < I used what it said in the Turing Walkthrough for the GUI and nothings happening. > Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using <4.1.1> |
Author: | Aange10 [ Sun Oct 16, 2011 2:15 pm ] |
Post subject: | Re: Clickable buttons |
Hmm, well sammi @ 16/10/2011, 12:59 pm wrote:
you're exit when GUI.ProcessEvent statement isn't being read, because it's not in the Main loop. You program is never getting to it. |
Author: | sammi [ Sun Oct 16, 2011 2:25 pm ] |
Post subject: | RE:Clickable buttons |
ohh ok thanks |
Author: | sammi [ Sun Oct 16, 2011 2:26 pm ] |
Post subject: | RE:Clickable buttons |
but they still aren't clickable....... |
Author: | Aange10 [ Sun Oct 16, 2011 2:30 pm ] | ||
Post subject: | RE:Clickable buttons | ||
You should check your other post, http://compsci.ca/v3/viewtopic.php?p=244915#244915 ... You pretty much asked the same question (Why aren't your buttons working) .. try
|
Author: | sammi [ Sun Oct 16, 2011 2:35 pm ] |
Post subject: | RE:Clickable buttons |
if i put the var YesButton things anywhere but where they are now i get an error message saying "procedure's may only be declared at the program, module or moniter level" i have no idea what that means |
Author: | Aange10 [ Sun Oct 16, 2011 2:44 pm ] | ||
Post subject: | Re: Clickable buttons | ||
If you would've followed the help on the other post, your code would look like this.
Now, you're program does exactly what you told it to. |
Author: | sammi [ Sun Oct 16, 2011 2:48 pm ] |
Post subject: | RE:Clickable buttons |
well that one lets me click it but it goes haywire when i do |
Author: | Aange10 [ Sun Oct 16, 2011 3:05 pm ] | ||
Post subject: | Re: RE:Clickable buttons | ||
sammi @ 16/10/2011, 1:48 pm wrote: well that one lets me click it but it goes haywire when i do
Think about what your telling it to do. All your telling it to do is put a statement. You're not telling it to leave the loop, or to re do the program. Try something like this:
Now, with that we added a variable to tell us if we hit the button. If we hit the button then we leave the loop. When we leave the loop the program finishes the Main Loop and repeats it. So at the top, when it repeats, we have it do what we want the buttons to do, then after it does what we wanted it to do we reset the buttons. Now, think of what you're telling the buttons to do, and what you actually want them to do. See if you can figure out how to make it all work properly. EDIT: Also, you need to define your procedures AFTER you've made your global variables, not before. |
Author: | sammi [ Sun Oct 16, 2011 3:25 pm ] |
Post subject: | RE:Clickable buttons |
oh ok i'll give that a try and see if i can figure it out |
Author: | sammi [ Sun Oct 16, 2011 3:31 pm ] |
Post subject: | RE:Clickable buttons |
i figured out another way to do it but it only works for one button....when i try to do it with the other button it gives me an error message... import GUI %%% WHAT I WANT THE BUTTON TO DO WHEN I CLICK IT%%% %procedure TryAgainButton %put "Ask the magic 8 ball another question" %end TryAgainButton %% DECLARING MY VARIABLES %% var Question : string %the typing cursor var Answer : int % part of the array var valid : boolean %number check var words : array 1 .. 11 of string %the answers %var Mouse.Where(350, 50, YesButton) %% PARTS OF THE ARRAY %% words (1) := "Yes" words (2) := "No" words (3) := "Maybe" words (4) := "Thats for me to know and you to find out ![]() words (5) := "Of course" words (6) := "I doubt it" words (7) := "In your dreams" words (8) := "Keep dreaming" words (9) := "How the heck am i suppossed to know?" words (10) := "Obviously" words (11) := "Absolutely" %%% Magic 8 Ball PROGRAM %%% procedure MagicBall cls() %refresh screen procedure ExitButton cls() loop valid := true % sets questions to valid until it hits check % Asking the question locatexy (200, 390) put "Ask the Magic 8-Ball a question" % drawing the ball Draw.FillOval (330, 250, 100, 100, brightred) % Getting a response locatexy (250, 250) get Question : * % Make sure the question contains no numbers for i : 1 .. length (Question) % Represents the Character of the string for b : 1 .. 9 % checks to see if the character, i, has a number. if Question (i) = intstr(b) then % If it does, it sets valid to false. valid := false % if it finds a number then it recognizes an improper question cls() exit end if end for end for locatexy (200, 100) % position of answer and "invalid" comment if valid then Answer := Rand.Int (1, 11) put words (Answer) delay (2000)% lets person read answer cls()%gets rid of the answer locatexy (200, 80) put "Would you like to ask another question?" else locatexy (200, 220) put "Thats not a question silly!!!" delay (1500) cls () end if loop var YesButton : int := GUI.CreateButton (250, 50, 0, "Yes", MagicBall) var NoButton : int := GUI.CreateButton (350, 50, 0, "No", ExitButton) exit when GUI.ProcessEvent end loop end loop end MagicBall end ExitButton MagicBall ExitButton |
Author: | Aange10 [ Sun Oct 16, 2011 3:57 pm ] | ||||||
Post subject: | RE:Clickable buttons | ||||||
Okay, your getting an error message because you can't define a procedure within a procedure. ... If you wanted you could make the second button's procedure say
Then the program would stop when you hit the button. ........ Though I'd like to point out that if you used the code above this one, that you could simply change
to make it do whatever you want... for example..
|
Author: | sammi [ Sun Oct 16, 2011 4:01 pm ] |
Post subject: | RE:Clickable buttons |
sorry i was going to use your way but my dad said this way would be easier (he just told me hes good at computer programming as soon as i read your answer) so i'll try your way instead. |
Author: | sammi [ Sun Oct 16, 2011 5:08 pm ] |
Post subject: | RE:Clickable buttons |
ok i ran into another problem.......when i click the no button, i want the message to pop up and then the buttons to disappear but i can't seem to make them disappear import GUI procedure ExitButton cls() put " Aww you can't tell me your done already....." delay(2000) put "ok fine......bye bye" end ExitButton cls() %% DECLARING MY VARIABLES %% var Question : string %the typing cursor var Answer : int % part of the array var valid : boolean %number check var words : array 1 .. 11 of string %the answers %var Mouse.Where(350, 50, YesButton) %% PARTS OF THE ARRAY %% words (1) := "Yes" words (2) := "No" words (3) := "Maybe" words (4) := "Thats for me to know and you to find out ![]() words (5) := "Of course" words (6) := "I doubt it" words (7) := "In your dreams" words (8) := "Keep dreaming" words (9) := "How the heck am i suppossed to know?" words (10) := "Obviously" words (11) := "Absolutely" %%% MAGIC BALL PROGRAM %%% procedure MagicBall cls()%refresh screen loop valid := true % sets questions to valid until it hits check % Asking the question locatexy (200, 390) put "Ask the Magic 8-Ball a question" % drawing the ball Draw.FillOval (330, 250, 100, 100, brightred) % Getting a response locatexy (250, 250) get Question : * % Make sure the question contains no numbers for i : 1 .. length (Question) % Represents the Character of the string for b : 1 .. 9 % checks to see if the character, i, has a number. if Question (i) = intstr (b) then % If it does, it sets valid to false. valid := false % if it finds a number then it recognizes an improper question cls () exit end if end for end for locatexy (200, 100) % position of answer and "invalid" comment if valid then Answer := Rand.Int (1, 11) put words (Answer) delay (2000) % lets person read answer cls () %gets rid of the answer locatexy (200, 80) put "Would you like to ask another question?" else locatexy (200, 220) put "Thats not a question silly!!!" delay (1500) cls () end if loop var YesButton : int := GUI.CreateButton (250, 50, 0, "Yes", MagicBall) var NoButton : int := GUI.CreateButton (350, 50, 0, "No", ExitButton) exit when GUI.ProcessEvent end loop end loop end MagicBall MagicBall |
Author: | Aange10 [ Sun Oct 16, 2011 5:17 pm ] | ||
Post subject: | Re: Clickable buttons | ||
If you watch carefully the buttons are going away properly.
This is what you're no button is doing. Nothing more, nothing less. When you hit the no button it clears your screen, it puts the message, it delays for 2 seconds, puts another message and thats it. It doesn't exit the loop (which is what is redrawing the buttons) it doesn't quit the game. The only thing it does is what is in the procedure's parameters. ......... Also, please put [ syntax="turing" ] before your code and [ /syntax ] after it. (With no spaces). It makes people want to help you more if they can read it |
Author: | sammi [ Sun Oct 16, 2011 5:21 pm ] |
Post subject: | RE:Clickable buttons |
oh im sorry! i didnt even know i could do that!!!!! |
Author: | sammi [ Sun Oct 16, 2011 7:38 pm ] | ||
Post subject: | RE:Clickable buttons | ||
me and my dad have tried everything and we still cant get the darn buttons to go away after i click 'no'. we think it has something to do with putting cls in somewhere but thats not working and we couldn't anything in the walkthrough can someone please help.
|
Author: | Aange10 [ Sun Oct 16, 2011 7:51 pm ] | ||||
Post subject: | Re: RE:Clickable buttons | ||||
sammi @ 16/10/2011, 6:38 pm wrote: me and my dad have tried everything and we still cant get the darn buttons to go away after i click 'no'. we think it has something to do with putting cls in somewhere but thats not working and we couldn't anything in the walkthrough can someone please help.
Try this
That should fix your problem. It indefinitely loops the drawling, so that it doesn't continue on to redrawing the buttons. It only delays the first time it execute, aswell. (That away you can't tell it's looping) also the quit command will stop the program, if you want to use that. ... Also, your global variables need to be defined BEFORE your procedures. (So move the extibutton procedure down, right above your magiball procedure) EDIT: Also, using
To draw your 8 ball would look much better ![]() |