
-----------------------------------
leafs911
Fri Jan 11, 2008 11:35 pm

having big time problems with procedurees
-----------------------------------
i am trying to execute procedures with keyboard input and click input (i am using a gui)
the problem i am having is that the buttons work fine but the keyboard input is not being recognized. i have checked and made sure that the the part of the code which get the input from the keboard and then give the corresponding output is correct (i took it out and ran it alone without the buttons\gui part. can someone please correct me?
thanks 


% The Car controller.
import GUI

View.Set ("graphics:360;200,nobuttonbar")

var chars : array char of boolean


    
    procedure Left
        locate (10, 5)
        put "Left"
        parallelput (1)
    end Left
    cls

    procedure Right
        locate (10, 5)
        put "Right"
        parallelput (2)
    end Right
    cls

    procedure Forward
        locate (10, 5)
        put "Forward"
        parallelput (4)
    end Forward
    cls

    procedure Back
        locate (10, 5)
        put "Back"
        parallelput (8)
    end Back

    
    procedure Exit
        GUI.Quit
        loop
            exit when GUI.ProcessEvent
        end loop
        Window.Hide (defWinID)
    end Exit
loop
    var bl : int := GUI.CreateButton (10, 155, 100, "Left", Left)
    var bf : int := GUI.CreateButton (130, 170, 100, "Forward", Forward)
    var br : int := GUI.CreateButton (250, 155, 100, "Right", Right)
    var bb : int := GUI.CreateButton (130, 140, 100, "Back", Back)
    var bcw : int := GUI.CreateButton (130, 10, 100, "Exit", Exit)

    loop
        exit when GUI.ProcessEvent
    end loop

    loop
        Input.KeyDown (chars)
        locate (4, 1)
        if chars (KEY_UP_ARROW) then
            Forward
        end if
        if chars (KEY_RIGHT_ARROW) then
            Right
        end if
        if chars (KEY_LEFT_ARROW) then
            Left
        end if
        if chars (KEY_DOWN_ARROW) then
            Back
        end if
    end loop
end loop


-----------------------------------
Tony
Fri Jan 11, 2008 11:43 pm

RE:having big time problems with procedurees
-----------------------------------
there is a clear lack of understanding of how the loops work in that code. If you can answer this question, then the solution to your question will be clear.

Consider the following code

loop
   put "Wait for it..."
end loop
put "Now!"

When will "Now!" be printed to screen?

-----------------------------------
leafs911
Sat Jan 12, 2008 12:03 am

RE:having big time problems with procedurees
-----------------------------------
well never cause the processor is processing the loop which it wont get get out of.

thanks for tip...i am ganna go look into it right now

-----------------------------------
leafs911
Sat Jan 12, 2008 12:38 am

Re: having big time problems with procedurees
-----------------------------------
i did it! thanks to Tony!

here is the code that works

% The Car controller.
import GUI

View.Set ("graphics:360;200,nobuttonbar")

var chars : array char of boolean



procedure Left
    locate (10, 5)
    put "Left"
    parallelput (1)
end Left


procedure Right
    locate (10, 5)
    put "Right"
    parallelput (2)
end Right


procedure Forward
    locate (10, 5)
    put "Forward"
    parallelput (4)
end Forward



procedure Back
    locate (10, 5)
    put "Back"
    parallelput (8)
end Back


procedure Exit
    GUI.Quit
    loop
        exit when GUI.ProcessEvent
    end loop
    Window.Hide (defWinID)
end Exit

var bl : int := GUI.CreateButton (10, 155, 100, "Left", Left)
var bf : int := GUI.CreateButton (130, 170, 100, "Forward", Forward)
var br : int := GUI.CreateButton (250, 155, 100, "Right", Right)
var bb : int := GUI.CreateButton (130, 140, 100, "Back", Back)
var bcw : int := GUI.CreateButton (130, 10, 100, "Exit", Exit)







loop

    Input.KeyDown (chars)
    locate (4, 1)
    if chars (KEY_UP_ARROW) then
        Forward
    end if
    if chars (KEY_RIGHT_ARROW) then
        Right
    end if
    if chars (KEY_LEFT_ARROW) then
        Left
    end if
    if chars (KEY_DOWN_ARROW) then
        Back
    end if
    exit when GUI.ProcessEvent
end loop


-----------------------------------
Tony
Sat Jan 12, 2008 1:05 am

Re: having big time problems with procedurees
-----------------------------------
well done :)

Also -- if you wrap your code in [syntax="turing"][/syntax] tags, rather than [quote], it will look much nicer ;)
