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

Username:   Password: 
 RegisterRegister   
 Getch input
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Walker




PostPosted: Sat Jun 05, 2004 8:24 pm   Post subject: Getch input

okay im using a keyboard for input and my code is

code:
 
    if hasch then
        getch (key)
    end if
    if key = ("w") then
        yy := yy + 20
    elsif chars ("s") then
        yy := yy - 20
    elsif chars ("d") then
        xx := xx + 20
    elsif chars ("a") then
        xx := xx - 20


i would ecpect this to move the xx and yy values up and down by using the w,s,a and d keys but instead is does nothing. What did i do wrong?
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Sat Jun 05, 2004 8:30 pm   Post subject: (No subject)

How about you get rid of the if hasch part. It seems redundant to me.

code:

loop
getch (key)
if key = "w" then
%...
end if
end loop


I'm not entirely sure what your "+ 20" thing was all about...I can only imagine that it has something to do with your locates? Well, that is if you are using ASCII art.
Otherwise, it probably has something to do with your xy-coords? I'm just guessing...
Cervantes




PostPosted: Sun Jun 06, 2004 7:38 am   Post subject: (No subject)

you switch from asking "is key = to whatever character" to "is chars = to whatever character". Confused

if you are using this for a game, read up on Input.KeyDown()
AsianSensation




PostPosted: Sun Jun 06, 2004 6:13 pm   Post subject: (No subject)

code:
var key : string (1)
var x, y : int := 0

loop
    if hasch then
        getch (key)
        if key = ("w") then
            y += 10
        elsif key = ("s") then
            y -= 10
        elsif key = ("d") then
            x += 10
        elsif key = ("a") then
            x -= 10
        end if
    end if
    drawfillbox (x, y, x + 10, y + 10, black)
end loop
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  [ 4 Posts ]
Jump to:   


Style:  
Search: