SA-MP Forums Archive
Keys by & operator - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Keys by & operator (/showthread.php?tid=171123)



Keys by & operator - RSX - 25.08.2010

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