Posts: 1,501
Threads: 19
Joined: Nov 2007
Reputation:
0
I'm not sure. I know the second version will make it so that if you press the key, it will still register it even if you're holding other keys. I'm not sure about the first version. I'm sure it does something similar. It looks like they both use bitwise functions.
Posts: 2,628
Threads: 32
Joined: Apr 2007
Reputation:
0
Since this has the same subject (almost), I'll just ask here.. :P
Whats the difference between "==" and "&" ? :P
Everyone uses "&" for keystates, so I've been wondering a long time :P
Posts: 105
Threads: 3
Joined: Jul 2007
Reputation:
0
The first one is a key being pressed (Not held). The second one is a key being released.
Larzi:
"==" is equal to obviously. "&" is binary AND. I also used to have a problem understanding why "&" is used, but then I had to learn subnetting. Look in Wikipedia for binary and, they have a good explanation. The goal is to be able to detect which combination of keys is being pressed, and not just one key.
No Keys:
00000000
Let's say Fire Key == 8
00010000
And Let's say Aim Key == 128
00010001
Get the point? This way we can detect a combination of keys instead of just assigning any numbers in sequence (i.e. 1,2,3,4).
Now we can detect just ONE of those keys, or all of them.
Is player holding Fire Key along with other keys we don't care about?
Current Keys:
00010001
We do an AND operation:
And operation means true and true, just like in English.
Current: 00010001
Fire key:00010000
Result is:00010000
The result is fire key. The player is holding fire key along with other keys. By the way, I wrote these binary values reversed, no idea why.
Posts: 143
Threads: 5
Joined: Mar 2008
Reputation:
0
my question was not "Whats the difference between "==" and "&" ?"
Posts: 2,628
Threads: 32
Joined: Apr 2007
Reputation:
0
Ty for explaining for me, lol :P
Biggest thanks to Don Correli who "explained" best :>