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

Username:   Password: 
 RegisterRegister   
 Buttons which change a variable
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cole




PostPosted: Sun Nov 11, 2012 3:42 pm   Post subject: Buttons which change a variable

What is it you are trying to achieve?
I want the user to click a button which will assign a string or value to a variable, then trigger an "if" statement. I would like to use the built in turing GUI if possible.


What is the problem you are having?
I can create the buttons, but the procedure assigned to the button will not trigger the "if" statement


Describe what you have tried to solve this problem
Putting parts of my code in the procedure. This proved too hard to do properly....


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing:

var counter, Buttons : int := 0
var userResponse : string
procedure hit
userResponse:="hit"
put userResponse
end hit
procedure stay
userResponse:="stay"
put userResponse
end stay
Buttons := GUI.CreateButton (10, 10, 0, "Hit", hit)
Buttons := GUI.CreateButton (55, 10, 0, "Stay", stay)

    loop
        exit when GUI.ProcessEvent
    end loop
   
   
    if userResponse="hit"
    then
    cls
    put "hello"
    end if




Please specify what version of Turing you are using
4.1.1



Thanks in advance for everyone's help!
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Sun Nov 11, 2012 3:47 pm   Post subject: Re: Buttons which change a variable

Do you know what GUI.ProcessEvent() does? Do you know when it will return true and drop you out of your loop?
cole




PostPosted: Sun Nov 11, 2012 5:37 pm   Post subject: Re: Buttons which change a variable

I used qui.quit and that seemed to work....


Thanks for the reply though
evildaddy911




PostPosted: Sun Nov 11, 2012 7:07 pm   Post subject: RE:Buttons which change a variable

your using the same variable for both buttons, won't that mess it up?
Dreadnought




PostPosted: Sun Nov 11, 2012 7:54 pm   Post subject: Re: Buttons which change a variable

evildaddy911 wrote:
your using the same variable for both buttons, won't that mess it up?

It doesn't mess it up but it does mean he loses the reference to the first button.


@Cole
GUI.ProcessEvent is a function that processes events for the buttons, like checking if they are clicked and such. It returns true when you quit the GUI module (which is why GUI.quit makes things work a bit).

However, once you drop out of your loop, you stop calling GUI.processEvent, so your buttons will no longer work, but you're if statement will execute.

Try to combine the loop and the if statement to both check for user input on the buttons and check the variable.
QuantumPhysics




PostPosted: Sun Nov 11, 2012 9:28 pm   Post subject: RE:Buttons which change a variable

So how do you actually create a button? Is GUI.createbutton(5) really all it takes? Turing should be a language to teach beginners. From personal preference that does not seem like it is even one step close to teaching a user how to make a button in C.
Dreadnought




PostPosted: Sun Nov 11, 2012 9:55 pm   Post subject: Re: Buttons which change a variable

QuantumPhysics wrote:
So how do you actually create a button? Is GUI.createbutton(5) really all it takes? Turing should be a language to teach beginners. From personal preference that does not seem like it is even one step close to teaching a user how to make a button in C.

Please don't derail this topic with a useless question which you seem to know the answer to ("from your personal experience").

If you are truly puzzled about the creation of a button, I suggest you read the GUI source code (it's actually quite well documented). If you want to discuss Turing design choices you should make your own thread.
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  [ 7 Posts ]
Jump to:   


Style:  
Search: