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

Username:   Password: 
 RegisterRegister   
 having big time problems with procedurees
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
leafs911




PostPosted: Fri Jan 11, 2008 11:35 pm   Post subject: 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


Quote:
% 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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Jan 11, 2008 11:43 pm   Post subject: 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
code:

loop
   put "Wait for it..."
end loop
put "Now!"

When will "Now!" be printed to screen?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
leafs911




PostPosted: Sat Jan 12, 2008 12:03 am   Post subject: 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




PostPosted: Sat Jan 12, 2008 12:38 am   Post subject: Re: having big time problems with procedurees

i did it! thanks to Tony!

here is the code that works

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




PostPosted: Sat Jan 12, 2008 1:05 am   Post subject: Re: having big time problems with procedurees

well done Smile

Also -- if you wrap your code in [syntax="turing"][/syntax] tags, rather than [quote], it will look much nicer Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 5 Posts ]
Jump to:   


Style:  
Search: