Keys by & operator
#1

So finaly i have searched and know what really & does, so as far as I remember, some of you does like this,
for example in code of OnPlayerKeyStateChange
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(OurActionKey==newkeys) Action();
    return 1;
}
But as & will always return bigger than one if the bigger one contains the smaller one (For Keys which are all 2^y)
i think it could be used as this :
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(0<(OurActionKey&newkeys)) Action();
    return 1;
}
or 0!= or 1<=
So, am I right, and which check would be faster? "0<", "0!=" or "1<="

Operator & does:
000000101010 = 42
000000000110 = 6
000000000010 = 42 & 6 = 2
(Gives binary one only if both are 1, and in our case, there's no partial mach because of only one 1 in check)

Advantage it gives - you can use action like jump, let's say while driving (I mean pressing "W" "A" "S" "D")
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)