Variable lossing state??

Look at the line _blockMinedFrame = 5;

 public override void Update(float dt)
        {
            base.Update(dt);

            if (_currentBlockMining != null)
                if (_currentBlockMining.Value.Worldlocation == _blockMining.Worldlocation)
                {
                    _timeMining += dt;
                    float frameCurrent = _timeMining / _timeTillMiningCompleate;
                    frameCurrent *= 7;
                    frameCurrent--;
                    _blockMinedFrame = 5;
                    if (_timeMining >= _timeTillMiningCompleate)
                    {
                        MineBlock();
                    }
                }
                else
                {
                    _blockMining = _currentBlockMining.Value;
                    _timeTillMiningCompleate = Block.LookupBlock(_blockMining.Id).Strenght;
                    _timeMining = 0;
                }

            _currentBlockMining = null;
        }

The line runs fine and sets the variable to 5, but the next time the update is called the variable is reset to -5;

here is how I call it

for (int i = 0; i < Mobs.Count; i++)
            {

                Mobs[i].Update(dt); //update each mob
            }

the weird thing is the other variables keep there state. No other places calls or sets this
variable. I even changed it to a property and put a break point on the set function and the only set is the one that I run.

I’m so confused right now, probably missing something really obvious.
Thanks guys

Are you sure blockMinedFrame is not decremented nor assigned elsewhere ? (ie: with visual’s “find all references” of this variable shows no other line than this one)
How is it declared/initialized ?

there are only 2 references to it. One is the one shown the other is a if statement checking that its greater than -1.

The class is only intizalized once.

I noticed that you are calling “base.Update(dt)” from within your override method. Are you possibly do an update to the variable in question in that method?

It also may provide some more information if you could post all of your relevant code… :slight_smile:

no this variable scope is private to this subclass only. Thought I’d posted that part of the code. I’ll post rest of class when I get home.

Hum… If it is set as 5 and never decremented, why checking if it is greater than -1. How do you decrement its value? That is the question the true question? Do you call another method to get its value ? with Ref? Out?
What does the debugger say when you step in or out when the next update is reached with the - 5 value? (ie debug the caller)

its set to 5 currently to eliminate any other logic issues I may have in my code. It should be set to math.floor(frameCurrent)

I was just making code simpler for debugging. Tracing debug not showing anything nether is watch.

Oddly the bug has fixed itself??
Did a clean and rebuild, after restart and closed antivirus down and now the variable is remembering state, I’m well perplexed.

For small to medium projects i always use rebuild instead of build to avoid this kind of case where you are scratching your head wondering why c# is loosing its mind… :laughing: (in my case it was if c ==2 was always false when c value was 2)