
-----------------------------------
isaiahk9
Mon Jul 28, 2008 7:46 pm

How can I press two keys with a different outcome for each key singularally and a combined effect?
-----------------------------------
The title either explains it all, or makes no sense.  But to put it in easier terms to understand, I plan on making a fighting game and I want J key to be the "basic attack", and the arrow keys to direct the avatar of the gamer.  To cut down on control keys, I thought combo-ing keys would make the game simpler (Up + J, Down + J, Right/Left + J , or just J would all initiate different attacks).
So to test if this was possible, I whipped this up : 



var key : array char of boolean
var key2 : array char of boolean
setscreen ("graphics")
loop
cls
    Input.KeyDown (key)
    Input.KeyDown (key2)
    

    if key (KEY_RIGHT_ARROW) and key2 (KEY_UP_ARROW) then
        Draw.FillBox (100 + 200, 100 + 200, 105 + 200, 105 + 200, black)

    elsif key2 (KEY_RIGHT_ARROW) then
    delay (100)
    if key2 (KEY_UP_ARROW) then
    else
        Draw.FillBox (100 + 100, 100, 105 + 100, 105, blue)
end if

    elsif key (KEY_UP_ARROW) then
        Draw.FillBox (100, 100 + 100, 105, 105 + 100, green)



    else
        Draw.FillBox (100, 100, 105, 105, red)

    end if
   delay (100)     
end loop



I want the black box to go off without either the green or blue boxes going off first.  Any clue how?  It's fundamental to my game.  If it's not possible, I could simplify my game, but I would like to know.
 - thanx

-----------------------------------
Euphoracle
Mon Jul 28, 2008 8:03 pm

RE:How can I press two keys with a different outcome for each key singularally and a combined effect?
-----------------------------------
You don't need 2 arrays of the same thing.  They'll be storing the same thing UNLESS you manage to release the key within the fraction of milliseconds of delay inbetween the calls.

-----------------------------------
Tony
Mon Jul 28, 2008 8:09 pm

RE:How can I press two keys with a different outcome for each key singularally and a combined effect?
-----------------------------------
Indeed, the name "key" is very misleading. Input.KeyDown record the entire keyboard (or as much of it as it can...). It helps to think of it in such terms.

Also, things like

elsif key2 (KEY_RIGHT_ARROW) then
delay (100)
if key2 (KEY_UP_ARROW) then 

are really weird... since the value of the "key2" doesn't change during the delay. And it seems strange to arbitrary slow down the game for a certain key press.

-----------------------------------
Euphoracle
Mon Jul 28, 2008 8:14 pm

RE:How can I press two keys with a different outcome for each key singularally and a combined effect?
-----------------------------------
What I don't think he is understanding is that this stuff is being checked every frame.  You'll want to write some sort of wrapper to determine when a key has been released.  KeyDown returns whether it is being pressed at that exact moment.  It is impossible to use only that for combinations, unless you are going to make a game about "can you press the keys at the exact same millisecond".  Key combinations work by determining when keys are released, or waiting for all required keys to be pressed at the same time.  It's the difference between pressing, say, Windows Key + D (on windows xp) and Windows Key + L (on windows xp) for Show Desktop and Lock Computer functionality.

It's a bit more complicated than is led to believe, and if it is designed an implemented well, there won't be any gripes about poor controls (see:  prerender frames & unreal