Getting to Know StandardGame and GameStates

My project hit a critical mass of unwieldliness and some redesign is now underway.  I decided to explore StandardGame and GameStates to give me what I was achieving with BaseGame and Node trees to define different areas in the game – attaching and detaching from the root Node as needed and using some monsterous switches to keep track of what was going on.

In trying to wrap my head around StandardGame and GameStates, I thought I would throw together a test app (based on the Tutorial/faq) that basically has three GameStates that can be displayed (activated seperately or in combination) to simulate in-game area changes, visual overlays, etc.

However, when trying to access the active state of a particular GameState I am getting a null pointer exception that I can't quite find a way to get beyond.  My idea is to pickup a keypress and then check the active status of the GameState in question and setActive to what is opposite of its current active status.

I have tried using:

gs2Bool = GameStateManager.getInstance().getChild("gamestate2").isActive();

to access the current active status of the state (in order to flip gs2Bool), and


to try to set the state directly (after flipping the boolean directly).

The exceptions thrown in both cases are essentially the same and note:

Jul 4, 2008 12:19:11 PM uncaughtException

SEVERE: Main game loop broken by uncaught exception


at worldgamestates.BaseGameState.update(

at Source)

at Source)

at Source)


In this case, line 68 is


I'm sure I'm just overlooking something, but I'm not sure what and haven't found any clues in the docs or in forum searches.  Any ideas?

Well… heh… pardon me.  I knew it was something simple…

It turns out that I was trying to access the GameState by its create() name and not its given (setName) name.  So, in this instance I was creating the GameState with

GameState2 gamestate2 = new GameState2("GS2");



and then trying to access it via "gamestate2" instead of "GS2".

O forum!  Thanks for being a great sounding board! (if even I only heard my very own echos herein :wink: