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

Username:   Password: 
 RegisterRegister   
 Can you set it to use two buttons at once
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Quakerstate98




PostPosted: Fri Jun 16, 2006 11:37 am   Post subject: Can you set it to use two buttons at once

I'm making a fighting game and i want to make it so you can press up arrow and right arrow to make a arched jump to the right.
I tried doing this way
if chars (KEY_UP_ARROW) and (KEY_RIGHT_ARROW) then
%Code
end if
but it doesn't work, says argument must be of teh same type, can someone help me it would be very appreciated.
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Fri Jun 16, 2006 11:44 am   Post subject: (No subject)

code:

if chars (KEY_UP_ARROW) and chars (KEY_RIGHT_ARROW) then
   %...


You did not specify where KEY_RIGHT_ARROW was coming from in your code. As it stands, K_R_A is simply an int; whereas when put in the context of the array chars() is stands as an index to a boolean.
NikG




PostPosted: Fri Jun 16, 2006 12:59 pm   Post subject: (No subject)

For future reference, just remember this: I believe MOST languages cannot figure out "if a=1 or 2 then" and you HAVE to write "if a=1 or a=2 then"...
Bored




PostPosted: Fri Jun 16, 2006 2:04 pm   Post subject: (No subject)

Delos wrote:
As it stands, K_R_A is simply an int;

Actually as it stands KEY_RIGHT_ARROW is a character that represents the right arrow key. ORD_RIGHT_ARROW however is an integer and is the ordinal value for the right arrow and thus KEY_RIGHT_ARROW = chr (ORD_RIGHT_ARROW) and ORD_RIGHT_ARROW = ord(KEY_RIGHT_ARROW). Technqualy KEY_RIGHT_ARROW = Í and ORD_RIGHT_ARROW = 205.
Quakerstate98




PostPosted: Fri Jun 16, 2006 2:23 pm   Post subject: Alright

Alright i see where your coming from, well i'll try it out and see what happens, if it doesn't work i'll be back lol
Delos




PostPosted: Fri Jun 16, 2006 3:33 pm   Post subject: (No subject)

Bored wrote:
Delos wrote:
As it stands, K_R_A is simply an int;

Actually as it stands KEY_RIGHT_ARROW is a character that represents the right arrow key. ORD_RIGHT_ARROW however is an integer and is the ordinal value for the right arrow and thus KEY_RIGHT_ARROW = chr (ORD_RIGHT_ARROW) and ORD_RIGHT_ARROW = ord(KEY_RIGHT_ARROW). Technqualy KEY_RIGHT_ARROW = Í and ORD_RIGHT_ARROW = 205.


...that's obviously what I meant Laughing!
Clayton




PostPosted: Fri Jun 16, 2006 3:54 pm   Post subject: (No subject)

well actually, you cannot have the same array hold two different values: this does not work:
Turing:

var key, keys : array char of boolean
loop
    Input.KeyDown (key)
    Input.Pause
    Input.KeyDown (keys)
    if key (KEY_RIGHT_ARROW) and keys (KEY_UP_ARROW) then
        %do whatever
    end if
    Input.Pause
end loop

you need to have two different variables to hold the two different variables Very Happy
Delos




PostPosted: Fri Jun 16, 2006 4:46 pm   Post subject: (No subject)

SuperFreak82 wrote:
well actually, you cannot have the same array hold two different values: this does not work:
Turing:

var key, keys : array char of boolean
loop
    Input.KeyDown (key)
    Input.Pause
    Input.KeyDown (keys)
    if key (KEY_RIGHT_ARROW) and keys (KEY_UP_ARROW) then
        %do whatever
    end if
    Input.Pause
end loop

you need to have two different variables to hold the two different variables Very Happy


Are you trying to tell me that if you'd used 'key' in both clauses of the if condition it would not work? I'm afraid you're sorely mistaken SuperFreak. I vaguely recall an example from F10 or thereabouts with a map of all chars controlled by Input.KeyDown(). When one pressed any key, it would highlight that point - and yes, one was able to press more than 1 key at once and have all register.

I don't have Turing here, but methinks something to this effect would work:

code:

proc putIKD (inArr : array char of boolean, start, finish : int)
  for i : start..finish
    put inArr (i), "" :  2..
  end for
end putIKD

var key : array char of boolean

loop
  Input.KeyDown (key)
  locate (1, 1)
  putIKD (key, 200, 210)  % This should cover the area encompassed by the arrow keys...if not, play around with the values.
end loop


Holding down two keys should result in two instances of 'true'. Tell me if that works.
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Fri Jun 16, 2006 6:01 pm   Post subject: (No subject)

well thats not wat i thought, and its not what i was taught either but, either way, ur probably right, i was just taught that you had to make a seperate array if you wanted to have more than one key activated, and i think i tried something with two keys for one array and i dont think i could get it to work, even though in theory it should

P.S. ur code above doesnt work Wink
Bored




PostPosted: Fri Jun 16, 2006 8:48 pm   Post subject: (No subject)

No one ARRAY will work as the way Input.KeyDown works is to simply turn the boolean value for that key to true if it's down and false if it isn't. The only difference between these arrays from a normal array is that the key is a character instead of an integer. Besides if you called it twice in a row wouldn't the same keys be pressed and thus you'd receive the EXACT same results ecpect in one in a million cases were the user released the key at that exact moment. This following code
code:
var key, keys : array char of boolean
loop
    Input.KeyDown (key)
    Input.Pause
    Input.KeyDown (keys)
    if key (KEY_RIGHT_ARROW) and keys (KEY_UP_ARROW) then
        %do whatever
    end if
    Input.Pause
end loop

Seems pretty unorthodox to me, as it would first check to see which keys are down, then wait for Input, then check again to see what was down. So basically it's the exact same as
code:
var key : array char of boolean
loop
    Input.KeyDown (key)
    if key (KEY_RIGHT_ARROW) and key (KEY_UP_ARROW) then
        %do whatever
    end if
end loop

As when it pauses the first time, well no keys were down thus we can safely say that the if statement will never happen. That means that we can skip the whole thing and leave the last Input.Pause. But then again that Input.Pause seems sorta strange and does nothing as the if would never happen until theres input so we're already waiting for it and adding the extra line is useless.
code:
var keys: array char of boolean
loop
    Input.KeyDown (keys)
    if keys (KEY_UP_ARROW) and keys (KEY_RIGHT_ARROW) then
        %run code
    elsif keys (THIS_THAT) then
        %run code
    end if
    %run code
end loop
Delos




PostPosted: Fri Jun 16, 2006 10:47 pm   Post subject: (No subject)

Heh, not bad for code written without a compiler present. Here's the fixed code and it appears to achieve what you were talking about - though I'm not positive.

code:

proc putIKD (inArr : array char of boolean, start, finish : int)
    for i : start .. finish
        put inArr (chr (i)), "" : 2 ..
    end for
end putIKD

var key : array char of boolean

loop
    Input.KeyDown (key)
    locate (1, 1)
    putIKD (key, 200, 210) % This should cover the area encompassed by the arrow keys...if not, play around with the values.
    exit when key ('q')
end loop
Bored




PostPosted: Fri Jun 16, 2006 11:46 pm   Post subject: (No subject)

Yes, that does show the whole thing, the only problem is that keybaords can only input so many keys simulatanioulsy which you can notice if you try that with a lot of keys, like say put it for the letter range, you will notice that if your try to add more keys after a certain point it will not process them. This is something that you must take into consideration when designing a program. If you have to many simultanious keys it will not be able to process. So lets say you have two players, turning, firing, and turboing. Unless you use certain keys like CRTL that are always read and do not cut off from the max number of input, you will have situations where the keys will not register. A second Input.KeyDown will not help either as the same priority is set for keys and thus it receives the same Input. I'm looking into seeing if there is a way around this.
Guest




PostPosted: Sat Jun 17, 2006 12:31 am   Post subject: (No subject)

I use seperate 'if' statments when I make programs that involve monitoring keystrokes. That way I believe more than one char can be read at the same time without using and/or. So if I use UP to do one thing, then RIGHT can also be done, so it does UP and RIGHT. But I can just solely do UP if I wish, without worring about RIGHT. But it does read the last keystroke pressed, so if I pressed UP, then DOWN, it would go down not up, until you release UP and press it again, I believe.
Bored




PostPosted: Sat Jun 17, 2006 4:59 am   Post subject: (No subject)

For a game that is what I'd do aswell but you can still only read so many keystrokes, the keyboard can only send so much information to the computer and so it will send the first keys pressed and send them constantly. Unill you release those keys others cannot be sent with the exception of say CTRL, SHIFT, ENTER, and a few others which can always be read.
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  [ 14 Posts ]
Jump to:   


Style:  
Search: