Problem with extended Classes

Monkey Forums/Monkey Programming/Problem with extended Classes

stefanbeckmann(Posted 2011) [#1]
What i intend to do:
I want to manage the GameStates of my Game with different Classes, which all extend my GameState base class. In my main Game file the ActiveGameState is stored in a Global variable of the base class type. The OnUpdate and OnRender methods call the ActiveGameState.Update and ActiveGameState.Render methods.

Whats happening in the code:
Each GameState extending GameState gets added to Global StateList in my GameState base class. If a GameState wants to change to another GameState the Function ChangeState gets called. ChangeState looks through the list, and if available sets the new state.

The problem:
When I set the ActiveGameState to the new GameState and Print the ActiveGameState.Name field (in the next line) the new GameStates Name gets printed. But in my main App the 'old' GameStates.Update and .Render methods are called. It's like the Global ActiveGameState gets never changed.

The Question:
Is what i want to do possible? Or am i missing some fundamental error with the class extension thing.

Regards,
stefan

Ps: sorry couldn't think of a better topic title

Here some code for better understanding:






Jesse(Posted 2011) [#2]
I don't know exactly what you are doing wrong but it is possible. My parallax scroller demo changes animation that way. it has about 16 animation groups that extend from a base format and changes animation depending on the action taken by assigning a extended animation to the base current animation variable.