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

Username:   Password: 
 RegisterRegister   
 Clickable buttons
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
sammi




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

Turing:


<import GUI

%%% WHAT I WANT THE BUTTON TO DO WHEN I CLICK IT%%%
procedure NextQuestionMenu
locate (1,1)
put "Ask the magic 8 ball another question"
end NextQuestionMenu

procedure ExitGame
locate (1,1)
put " Awww you can't tell me your done already....." 
end ExitGame


%% 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"

%% PROGRAM%%%%%
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?"
   var YesButton : int:= GUI.CreateButton (250, 50, 0, "Yes", NextQuestionMenu)
   var NoButton : int:= GUI.CreateButton (350, 50, 0, "No", ExitGame)
   
   
else
    locatexy (200, 220)
   put "Thats not a question silly!!!"
   delay (1500)
   cls()
end if



end loop

loop
exit when GUI.ProcessEvent
end loop
>



Please specify what version of Turing you are using
<4.1.1>
Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: Sun Oct 16, 2011 2:15 pm   Post subject: Re: Clickable buttons

Hmm, well

sammi @ 16/10/2011, 12:59 pm wrote:

Turing:

end loop

loop
exit when GUI.ProcessEvent
end loop




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.
sammi




PostPosted: Sun Oct 16, 2011 2:25 pm   Post subject: RE:Clickable buttons

ohh ok thanks
sammi




PostPosted: Sun Oct 16, 2011 2:26 pm   Post subject: RE:Clickable buttons

but they still aren't clickable.......
Aange10




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

loop
       var YesButton : int:= GUI.CreateButton (250, 50, 0, "Yes", NextQuestionMenu)
   var NoButton : int:= GUI.CreateButton (350, 50, 0, "No", ExitGame)
    exit when GUI.ProcessEvent
end loop
sammi




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




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

Turing:

import GUI

%%% WHAT I WANT THE BUTTON TO DO WHEN I CLICK IT%%%
procedure NextQuestionMenu
    put "Ask the magic 8 ball another question"
end NextQuestionMenu

procedure ExitGame
    put " Awww you can't tell me your done already....."
end ExitGame

%% DECLARING MY VARIABLES %%
var Question : string %the typing cursor
var valid : boolean := true %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 Smile"
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"

%% PROGRAM%%%%%
loop
    valid := true % Reset the question value
    % 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
        put words (Rand.Int(1,11)) % CHANGEd
    else
        locatexy (200, 220)
        put "Thats not a question silly!!!"
        delay (1500)
        cls ()
    end if
    locatexy (200, 20)
    put "Would you like to ask another question?"
    loop
        var YesButton : int := GUI.CreateButton (250, 50, 0, "Yes", NextQuestionMenu)
        var NoButton : int := GUI.CreateButton (350, 50, 0, "No", ExitGame)
        exit when GUI.ProcessEvent
    end loop
end loop


Now, you're program does exactly what you told it to.
sammi




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




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

Turing:

import GUI

%% DECLARING MY VARIABLES %%
var Question : string %the typing cursor
var valid : boolean := true %number check
var picked_button_1, picked_button_2 : boolean := false
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 Smile"
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"
%%% WHAT I WANT THE BUTTON TO DO WHEN I CLICK IT%%%
procedure NextQuestionMenu
    picked_button_1 := true
end NextQuestionMenu

procedure ExitGame
    picked_button_2 := true
end ExitGame


%% PROGRAM%%%%%
loop
    cls
    if picked_button_1 = true then
       put "Ask the magic 8 ball another question"
    elsif picked_button_2 = true then
       put " Awww you can't tell me your done already....."
    end if
    picked_button_2 := false % Reset the buttons
    picked_button_1 := false % Reset the buttons
    valid := true % Reset the question value
    % 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
        put words (Rand.Int(1,11)) % CHANGEd
    else
        locatexy (200, 220)
        put "Thats not a question silly!!!"
        delay (1500)
        cls ()
    end if
    locatexy (200, 20)
    put "Would you like to ask another question?"
    loop
        var YesButton : int := GUI.CreateButton (250, 50, 0, "Yes", NextQuestionMenu)
        var NoButton : int := GUI.CreateButton (350, 50, 0, "No", ExitGame)
        exit when GUI.ProcessEvent
        if picked_button_1 = true or picked_button_2 = true then
            exit
        end if
    end loop
end loop


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.
sammi




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




PostPosted: 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 Smile"
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
Aange10




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

code:

proc ExitButton
quit
end ExitButton


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

Turing:

    if picked_button_1 = true then
       put "Ask the magic 8 ball another question"
    elsif picked_button_2 = true then
       put " Awww you can't tell me your done already....."
    end if


to make it do whatever you want... for example..

Turing:

    if picked_button_1 = true then
      locatexy(maxx div 2, maxy div 2)
       put "Ask the magic 8 ball another question"
       delay(2000)
       cls
    elsif picked_button_2 = true then
       put " Awww you can't tell me your done already....."
      delay (2000)
      put "Alright, goodbye!"
      delay (1000)
      quit
    end if
sammi




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




PostPosted: 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 Smile"
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
Aange10




PostPosted: Sun Oct 16, 2011 5:17 pm   Post subject: Re: Clickable buttons

If you watch carefully the buttons are going away properly.

Turing:

procedure ExitButton
cls()
put " Aww you can't tell me your done already....."
delay(2000)
put "ok fine......bye bye"
end ExitButton


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
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 2  [ 18 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: