
-----------------------------------
Jesse.A
Sun May 25, 2014 1:34 pm

Can you have if statements in with GUI buttons?
-----------------------------------
What is it you are trying to achieve?
I am trying to use if statements with buttons.

What is the problem you are having?
I realy have no idea how i would go about doing it.


Describe what you have tried to solve this problem
I have messed around a little bit but nothing seems to be working.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)






import GUI
var button1, button2, button3 : int
var x : string
forward procedure display


procedure menu
    button1 := GUI.CreateButton (150, 200, 0, "Button1", display)
    button2 := GUI.CreateButton (250, 200, 0, "Button2", display)
    button3 := GUI.CreateButton (350, 200, 0, "Quit", GUI.Quit)
    
    loop
    if button1 = 1 and GUI.ProcessEvent then
    x := "1"
    exit
    elsif button2 = 1 and GUI.ProcessEvent then
        x := "2"
        end if
        end loop
end menu

body procedure display
         put "You pressed button" +x
end display
%main
menu
display





Please specify what version of Turing you are using
4.1.1

-----------------------------------
Insectoid
Sun May 25, 2014 4:01 pm

RE:Can you have if statements in with GUI buttons?
-----------------------------------
Instead of using an if statement, have your display procedure take x as a parameter and pass it on your button lines.

[code]button1 := GUI.CreatButton (150, 200, 0, "Button1", display(1))[/code]

-----------------------------------
Zren
Sun May 25, 2014 8:14 pm

Re: RE:Can you have if statements in with GUI buttons?
-----------------------------------
Instead of using an if statement, have your display procedure take x as a parameter and pass it on your button lines.



That doesn't work. Turing doesn't support lambdas, so you can't make simple callbacks like that.

-----------------------------------
Tony
Mon May 26, 2014 2:31 am

RE:Can you have if statements in with GUI buttons?
-----------------------------------
That's not lambda (in a way of anonymous function definition). The display is assumed to be already defined, and here it's referenced with an argument. I'm pretty sure that this works, although in a non-documented way.

Oddly enough, there's [tdoc]GUI.GetEventWidgetID[/tdoc], which could be used to distinguish between different widgets calling the same procedure.

-----------------------------------
Jesse.A
Mon May 26, 2014 8:35 pm

RE:Can you have if statements in with GUI buttons?
-----------------------------------
Thank you very much!

-----------------------------------
Zren
Mon May 26, 2014 8:56 pm

Re: RE:Can you have if statements in with GUI buttons?
-----------------------------------
That's not lambda (in a way of anonymous function definition). The display is assumed to be already defined, and here it's referenced with an argument. I'm pretty sure that this works, although in a non-documented way.

Oddly enough, there's 

So wait, calling a procedure with arguments returns a value? That value being a new procedure without parameters? What version of Turing supports this?

-----------------------------------
Tony
Tue May 27, 2014 12:48 pm

RE:Can you have if statements in with GUI buttons?
-----------------------------------
I don't remember this well, you might be right -- an argumented procedure might been to return a procedure without parameters. Turing does support procedures as types -- see [tdoc]subprogramType[/tdoc]
