It looks to me like the program is behaving in exactly the way you told it to. Perhaps you're confused about the semantics.
This is what happens when you create a StateOne:
|
Of course it does what I told it to! I just didn't tell it the right thing to accomplish what I'm trying to. I'm not accusing the compiler of doing something wrong, just myself. I'm trying to figure out what I'm doing wrong here.
This is what I'm trying to figure out:
What is the best ways I initialize the private variables in the GameState class and then later create a State object without this test returning false when I don't want it to:
1 2 3
|
bool shouldChange = (nextState != STATE_NULL);
if (shouldChange) {
//...
|
This is what happens when you create a StateOne:
|
That is very helpful, thanks!
I was not understanding why my changeState function fails each iteration of the while loop. All I know is that the nextState variable is set back to null each iteration of the while loop.
Now, I've slept on the problem a bit and I realized what may be going wrong:
In the main while loop, when I run currentState->runLogic(); and then it runs setNextState(newState), StateOne.nextState is getting set to the newState, not GameState.nextState like I intended.
Then in the main loop when changeState runs and checks for whether nextState is STATE_NULL or some other value it finds it is STATE_NULL because it was never changed. I only changed StateOne.nextState not GameState.next state. I forgot the setNextState() procedure is public so the derived class inherits it.
It was stupid of me for going so long without noticing that! Anyway let me know what you think.
Thanks so much for all your help!