Note that there are some explanatory texts on larger screens.

plurals
  1. POBitwise Logic behaviour (Boolean Logic) The structure in my code seems wrong!
    primarykey
    data
    text
    <p>Got a cool one this time, bit logic / boolean logic question!</p> <p>I am currently working in Visual Studio 2010 using C# as language and I am trying to keep track of some states using a [Flags] enum.</p> <p>I have used them several times (and frankly find them extremely usefull!!)</p> <p>It has 5 states all powers of 2 ofc no problems anywhere, the name is characterState (variable in which I store the values)</p> <p>In the following code sample:</p> <pre><code>private void DebugLogState() { //Check and log the current state of the character //If a state matches, play it's respective animation if ((currentCharacterState &amp; Controller_2D.CharacterState.Idle) &gt; 0) { Debug.Log("Idle state is active, log from object: Controller_2D"); } if ((currentCharacterState &amp; Controller_2D.CharacterState.Walking) &gt; 0) { Debug.Log("Walking state is active, log from object: Controller_2D"); } if ((currentCharacterState &amp; Controller_2D.CharacterState.Running) &gt; 0) { Debug.Log("Running state is active, log from object: Controller_2D"); } if ((currentCharacterState &amp; Controller_2D.CharacterState.Jumping) &gt; 0) { Debug.Log("Jumping state is active, log from object: Controller_2D"); } if ((currentCharacterState &amp; Controller_2D.CharacterState.Crouching) &gt; 0) { Debug.Log("Crouching state is active, log from object: Controller_2D"); } } </code></pre> <p>Now what I was hoping for is comparing 01011 (or any other permutation where idle is set to 1) with IDLE state (01000) &amp; them both and check > 0 to check if IDLE = true. I got an alarm in my head saying RECODE THIS NOW!!! But I'm just starting to stare and stare and wonder what the best way is.</p> <p>Feel free to help me find what is going to be the best check for IDLE state, I will try comparing with some of my older enum code in the meanwhile. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload