
-----------------------------------
Walker
Sat Jun 05, 2004 8:24 pm

Getch input
-----------------------------------
okay im using a keyboard for input and my code is

  
    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?

-----------------------------------
Delos
Sat Jun 05, 2004 8:30 pm


-----------------------------------
How about you get rid of the if hasch part.  It seems redundant to me.


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
Sun Jun 06, 2004 7:38 am


-----------------------------------
you switch from asking "is key = to whatever character" to "is chars = to whatever character".  :?

if you are using this for a game, read up on Input.KeyDown()

-----------------------------------
AsianSensation
Sun Jun 06, 2004 6:13 pm


-----------------------------------
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
