Computer Science Canada

Getch input

Author:  Walker [ 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?

Author:  Delos [ Sat Jun 05, 2004 8:30 pm ]
Post 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...

Author:  Cervantes [ Sun Jun 06, 2004 7:38 am ]
Post 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()

Author:  AsianSensation [ Sun Jun 06, 2004 6:13 pm ]
Post 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


: