ID:2327546
 
Resolved
The |= and ^= operators did not handle null correctly, so an existing numeric value would be cleared when ORed or XORed with null when instead they should have been left alone.
BYOND Version:511
Operating System:Windows 7 Ultimate 64-bit
Web Browser:Firefox 57.0
Applies to:Dream Daemon
Status: Resolved (512.1400)

This issue has been resolved.
Descriptive Problem Summary:
x |= y acts differently than x = x | y
Specificaly in the case when y is null, the first method will set x to 0 and the second method it will result in x being unchanged.

Code Snippet (if applicable) to Reproduce Problem:
var/foo = 4
foo |= null

var/bar = 4 | null


Expected Results:
foo and bar should equal the same thing

Actual Results:
foo is 0, bar is 4

Does the problem occur:
Every time?
Yes
In other games?
Even in test projects
In other user accounts?
Yes
On other computers?
Yes

When does the problem NOT occur?
It's unknown when this first started happening but it's a problem at least in the most recent versions of 511 and 512

Workarounds:
Just use the method that gives the results you want. Normally that's x = x | y.
I'm not sure this is worth changing, to be honest. The reason it behaves this way is to shortcut the var write when it's not necessary, and in a real project you'd never want to use |= null on a var meant to contain a number.
The problem came up in a loop

for(var/_key in user.keys_held)
movement_dir |= GLOB.movement_keys[_key]


In cases where the key held isnt a key designated for movement it would null out the previous values added in.
Oh, I see what you're saying. The problem is foo is being cleared by the |= operator in a case where it should be left alone.
Lummox JR resolved issue with message:
The |= and ^= operators did not handle null correctly, so an existing numeric value would be cleared when ORed or XORed with null when instead they should have been left alone.