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

Username:   Password: 
 RegisterRegister   
 small turing problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wallc++




PostPosted: Fri Apr 03, 2009 12:13 pm   Post subject: small turing problem

im useing turing 4.1


i need to know how to use keys for different commands in a program.

so far i know how to use arrow keys.
this is how im using them in my program

if chars (KEY_LEFT_ARROW) then
intX := intX - 1
end if

its code to make a dot move up

i want to use the space key to clear the screen but i dont know how i tell turing that i want to use space

if this makes little sence i posted all the code



%Etc A Sketch Program

var intX : int := 100 %initial x position of the etch

var intY : int := 100 %initial y position of the etch

var chars : array char of boolean
var intYchange : int := 1
var intXchange : int := 1
var intdotcolour : int := 0
%This is the main loop running program
Draw.Cls

View.Set ("graphics:639;479, nobuttonbar")

Draw.FillBox (0, 0, maxx, maxy, 7)
loop
delay (2)
Input.KeyDown (chars) %grabs the key that is held down

%Up arrow is pressed

if chars (KEY_UP_ARROW) then
intY := intY + 1

end if

%Right arrow is pressed

if chars (KEY_RIGHT_ARROW) then
intX := intX + 1

end if

%Left arrow is pressed

if chars (KEY_LEFT_ARROW) then
intX := intX - 1

end if

%Down arrow is pressed

if chars (KEY_DOWN_ARROW) then
intY := intY - 1

end if

%space key is pressed it will clear the screen
this is where i want to put the space if statment



randint (intdotcolour, 1, 15)
Draw.Dot (intX, intY, intdotcolour)

end loop




thanks for the help
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Fri Apr 03, 2009 12:44 pm   Post subject: RE:small turing problem

You've already got everything you need. You can index the chars array by characters too:

Turing:
if chars ( ' ' ) then
    % Do stuff here, like clearing the screen...
end if


Note the use of single quotes ( ' ) instead of double quotes ( " ) to distinguish between a char and a string.
wallc++




PostPosted: Wed Apr 08, 2009 9:18 am   Post subject: Re: small turing problem

ok same problem just with the s key
DemonWasp




PostPosted: Wed Apr 08, 2009 1:19 pm   Post subject: RE:small turing problem

Try thinking about it for a moment. How does detecting an 's' character differ from detecting a space ' ' character?
wallc++




PostPosted: Wed Apr 08, 2009 8:27 pm   Post subject: Re: small turing problem

great you've been alot of help thanks just one more thing is there a cammand or function to clear text from the screan?
Dusk Eagle




PostPosted: Wed Apr 08, 2009 10:10 pm   Post subject: Re: small turing problem

The command you are looking for is cls.
wallc++




PostPosted: Thu Apr 09, 2009 12:10 am   Post subject: Re: small turing problem

i tried Cls but it didnt work. i managed to clear it but it cleared everything off the screen. what if i used the fork cammand?
DemonWasp




PostPosted: Thu Apr 09, 2009 10:08 am   Post subject: RE:small turing problem

Slow down there. This "fork" command you speak of is a pit of quicksand - once you venture in there, you will be lost forever. The fork command has a few uses, but they're pretty few and far between. The biggest one is probably to teach new students to recognise danger when they see it. Using fork brings in multithreading, which is a rather complicated and difficult subject even for seasoned programmers. Debugging multithreaded applications is usually nightmarish. Stay away from it in Turing, wait until you're in a competent language before venturing down that hazard-laden road.

If you want to clear the entire screen, then cls() or Draw.Cls() will do that for you. If you only want to clear some portion of the screen, you have a few options. First, if the screen is outputting text (not images or similar), what you should do is use Text.Locate ( row, column ) to go to that line, then use put "". This will overwrite whatever is on that line. If you want to clear some portion of the screen in graphics mode, then what you need to do is use a Draw.FillBox call that draws to the background colour (defaults to white).
Sponsor
Sponsor
Sponsor
sponsor
RYAN191




PostPosted: Thu Apr 09, 2009 5:27 pm   Post subject: RE:small turing problem

just try cls or draw.cls
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  [ 9 Posts ]
Jump to:   


Style:  
Search: