Comparing key masks.
#1

Hey! I was scripting a keybind script, where I ran into an issue with key binds.

So what I'm doing is to compare 2 different key masks and see if the key combinations are pressed.
This is what I tried to do:

Код:
if(newkeys & keymask2)
But the problem for that was, any key that's in keymask 2 would pass. That works just fine for a single key bind, but if I require a combination, any of the keys would pass. I know I could do this:

Код:
if(newkeys == keymask2)
But in that case, the bind wouldn't get called if any other buttons are pressed down.
Do I really have to use a loop to achieve this functionality or is there a better way?

Thanks in advance.


Currently I'm looping through the keys and checking them against keymask2 and then newkeys, if any of them fail, I break the loop. That currently seems the only working option to me, but rather inefficient.
Reply
#2

Well I really didn't understand what you actually meant to say, your poor choice of words I guess.
But here's the thing, if you need to check if player is holding 2 keys combined, you can first combine them using |, then check it with &
PHP код:
if(newkeys & (keymask2|keymask3)) 
so you could check which key is being held with keymask2 so you could do different binds.


If thats not what you want please elaborate more or even put your current loop here so we could help you.
Reply
#3

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
Well I really didn't understand what you actually meant to say, your poor choice of words I guess.
But here's the thing, if you need to check if player is holding 2 keys combined, you can first combine them using |, then check it with &
PHP код:
if(newkeys & (keymask2|keymask3)) 
so you could check which key is being held with keymask2 so you could do different binds.


If thats not what you want please elaborate more or even put your current loop here so we could help you.
Didn't you get the point, that I got 2 Keymasks - the newkeys and the keymask2?

Player defines which keys are in the keymask2, it might even be all the keys or just one. So your suggestion doesn't work. If any of they keys that are found in keymask2 are pressed, the if statement is true and it doesn't require the rest of the keys and breaks the combinations (which is the point of this topic).

Looks like a loop is my best bet to get this working.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)