Struglling with Appstates

Let’s say I have 3 AppStates: Main Menu/ Pause Menu/ Highscore Menu

in Simpleinitapp I switched to Main Menu, and I made buttons in Main Menu, so my question is how to switch from Main Menu to Play Menu or High scores menu once I click on a button?

I am using tonegod gui

You detach your Main Menu AppState and attach your Play Menu AppState…?

and how Can I get the current app state?

There may be many app states running at a given time. There is no “current app state”.

Have you looked at the javadoc for AppStateManager?

Actually I have never used AppstateManager a lot before, but I needed it lately, I have thought of something like that:

first I make a package called Variables.

I make a new class called global variables and I do like:

int CurrentAppState = 1; // which means main menu 

boolean SwitchedToMainMenu = true;

boolean SwitchedToGameMenu = false;

then when I click on a button for example play button:

Variables.globalvariables.CurrentAppState = 2; // which means game Menu

and after that in the update on Main.java:

if(Variables.globalvariables.SwitchedToGameMenu == false && Variables.globalvariables.CurrentAppState == 2) {

Variables.globalvariables.SwitchedToGameMenu = true; 

Variables.globalvariables.SwitchedToMainMenu = false; 

//then after that detach the MainMenu appstate and attach the Game Appstate
}

Will it work like that? I mean would it be buggy or something? or is there a better solution?

P.s: I am planning to do an android game

For a same case, I use a PageManager. It know what is the current page, how to show, to hide page,…

https://github.com/davidB/jme3_ext/blob/master/src/main/java/jme3_ext/PageManager.java#L18

My page are define via enum, and use the following code to switch :

 pageManager.goto(Pages.Welcome.ordinal())

A sample project that use it :

is it the only way available?

Just keep a list of your AppStates when you create them? You seem to fall into the trap of wanting a library to do what your application is supposed to do.

No, there are lot of way to Rome.

But if you use AppState, you’ll use attach/detach and or setEnable(true/false).

So let’s say I have 3 appstates Main Menu State/ Game Menu State/Pause Menu State

Now when the application starts I switch to Main Menu State , and Inside Main Menu State I created the buttons which is : play and quit , so when a player click on play , I want to disable Main Menu State and enable the other one, so how can I disable it

I don’t use t0neg0dUI, but you can see :

jme3_skel is a basic sample application with several pages : Welcome, In game, config.

Wow that’s so cofusing ;| ty anyways I will try to find a solution :smiley:

stateMgr.getState(MainMenuState.class).setEnabled(false);
…or…
stateMgr.detach(getState(MainMenuState.class))

Personally, I’m having trouble figuring out where your confusion is.

You can see how I use app states here:

Essentially, app states are a way to temporarily “extend” the application’s functionality. As such they are useful for lots of things… “screen management” is just one small thing.

1 Like

Omg man you saved my life !!! Thank you very much it’s working!!!

you are awesome :smiley: you can close this topic now :slight_smile:

That’s why I suggested looking at the javadocs for AppStateManager as it would have shown you how to grab an existing state, etc… If you don’t know how to pull up javadocs then you really should find out.

I did know about getState but I didnt know that I could use it like that :smiley: anyways ty a lot man :slight_smile: