25.08.2010, 11:47
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
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 :
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")
for example in code of OnPlayerKeyStateChange
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(OurActionKey==newkeys) Action();
return 1;
}
i think it could be used as this :
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(0<(OurActionKey&newkeys)) Action();
return 1;
}
So, am I right, and which check would be faster?

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")