Quick question

01/16/2011 19:39 Syst3m_W1z4rd#1
I know &= & |= are assignment for opreators, but when do I use what.
The question was related to hybrids source.

Example:
Code:
            this.Entity.Spawn.StatusFlag &= ~StatusFlag.Fly;
            this.Entity.Spawn.StatusFlag |= StatusFlag.Dead;
Why would it not be?
this.Entity.Spawn.StatusFlag &= ~StatusFlag.Dead;
or
this.Entity.Spawn.StatusFlag |= StatusFlag.Fly;

I tried look up at msdn, but didn't really get it.

Thank you.
01/16/2011 20:46 © Haydz#2
The operators you show are binary/bitwise operators.

OR = |
NOT = ~
AND = &

Basically:

&= ~Flag (Removal of a flag from BitField)
|= Flag (Addition of a flag into BitField)

I could go on to quote various information from Wikipedia to assert my intelligence, but I'll just provide the link.

Bitwise Operations

In your example, I assume it is the death handler, which removes anything you can't do while dead, and adds the death + ghost flags.
01/16/2011 22:31 Syst3m_W1z4rd#3
Ahhh thank you. That's all I needed to know :)
01/17/2011 00:32 pro4never#4
The handy thing about bit operations is you don't have to worry about 'double reversing' or whatever...

IE:

Client.Dead != Client.Dead would simply reverse a bool... but if you're working with a bit field and do

Client.Flags &= ~Flags.BlueName;

You simply set bluename to false and remove any related status effect from the 'pool' and such. It makes things nice and simple for handling effects.

Sadly I still haven't switched over simply because I already need a dictionary to control the duration of an effect but they are definitely very useful. I suppose I could always switch to using my DAQ system instead.. but w/e.
01/17/2011 01:15 FuriousFang#5
Quote:
Originally Posted by pro4never View Post
The handy thing about bit operations is you don't have to worry about 'double reversing' or whatever...

IE:

Client.Dead != Client.Dead would simply reverse a bool... but if you're working with a bit field and do

Client.Flags ~= Flags.BlueName;

You simply set bluename to false and remove any related status effect from the 'pool' and such. It makes things nice and simple for handling effects.

Sadly I still haven't switched over simply because I already need a dictionary to control the duration of an effect but they are definitely very useful. I suppose I could always switch to using my DAQ system instead.. but w/e.
You just gave me an awesome idea =]
Thanks!
01/17/2011 20:00 _DreadNought_#6
It's explained in Hybrid tut's in the programming section for conquer.