Application State : Doc error

Sounds like you aren’t setting initialized to true… so you are getting reinitialized on every update.

pspeed said:
Sounds like you aren't setting initialized to true... so you are getting reinitialized on every update.


Yeap! That's right! initialize doesn't gets true (but I was wondering as well, am I doing it correctly with appstate and simpleapplication being used here?...)

I only looked quickly. It looks like your XML is not referring to your controller class “Menu”, though. Maybe there was something lost in translation for posting to the forum.

Mm… I double checked, nothing really, everything’s up there and nothing was lost during the posting on the forum. I kinda tweaked around with the code, and finally managed to stop the application from updating nifty’s screen non-stop but isInitialized() still returns a false even though I forcefully set it up as true when first called “setActive()” which is setEnabled(), something like this:



On Menu.java:

[java]

private boolean initialized = false;



… // some other methods omitted for quick view…



@Override

public void initialize(AppStateManager stateManager, Application app) {

if(intiialized){



}

}



//this methods gets called and supposedly should be altering the variable within so initialize() can run…

public void setActive(boolean activate){

initialized = true;

}



[/java]



And over on the RunningApp.java

[java]



public void simpleInit(){

Menu m = new Menu();

if(isInitialized()){

m.setActive(m);

stateManager.attach(m);

}

}



[/java]



setActive() is equivalent to setEnable(). It could be that I’m not on the nightly update, so the name still sticks back to the old one as setActive(). The result of the run shows no nifty’s screen appearing but this could be due to initialize is false…

I also notice that initialize() don’t get naturally called first so… yeah. :confused:

What is isInitialized() in this doing? I ask because it looks odd.

[java]

public void simpleInit(){

Menu m = new Menu();

if(isInitialized()){

m.setActive(m);

stateManager.attach(m);

}

}[/java]



Just in case, you should update since it looks like you are still running the ancient stock alpha 4… who knows what problems are lurking to be found.



initialize() is what should be setting initialized to true… not setActive. active/enabled != initialized. You can be initialized but still disabled… and you can be enabled and not initialized (ie: it will work right when it is finally attached+initialized). Many many many persistent states will be this way. For example, I have some screen-based app states that get attached disabled during simpleInit and only become enabled when a key is pressed.

pspeed said:
initialize() is what should be setting initialized to true... not setActive. active/enabled != initialized. You can be initialized but still disabled... and you can be enabled and not initialized (ie: it will work right when it is finally attached+initialized). Many many many persistent states will be this way. For example, I have some screen-based app states that get attached disabled during simpleInit and only become enabled when a key is pressed.

I see. I thought so as well.. but I began typing illogically after noticing that it doesn't work no matter how many times i tweaked.

pspeed said:
What is isInitialized() in this doing?

Nothing much, really, just receiving this:

[java]
public boolean isInitialized(){
return initialized;
}
[/java]

pspeed said:
Just in case, you should update since it looks like you are still running the ancient stock alpha 4… who knows what problems are lurking to be found.

I want to update, but previously after enabling the nightly updates, I had problems with nifty-gui when loading up images with transparency. The problem was discussed in this topic over here. And I don't know which version of update I was on that caused those problems, so, I continue to stick with the old stock jME by re-installing the platform again. At least, nifty works for some items (so far... just the new panels-style aren't showing proper functionalities yet), except that I don't know how old Nifty is with the early alpha 4.

if initialize() sets initialized to true… then you should be able to run it in a debugger and see that when isInitialized() is called it is returning that value. Or put a println or a log or something in there. There really shouldn’t be any magic happening.



regarding your own isInitialized() I just thought it was odd to check if your application is initialized in simpleInit(). It either always will be or always won’t be… but it’s pretty odd.

For the record, here is the basic app state lifecycle:



setEnabled() (or the now-ancient setActive in your case) is independent of initialization and can be called pre or post initialization. This simply says whether the state is enabled or not. disabled states won’t have their update() method called if they are attached. setEnabled() should set a flag so that isEnabled() returns the appropriate value. If isEnabled() is false then your app state’s update method will never be called (though initialize() will be).



stateManager.attach() : attaches the app state to the state manager. on the next update loop pass the state will be initialized if isInitialized() returns false.



initialize() : called by state manager during the update loop if isInitialized() returns false.

And you know, if you are extending AbstractAppState then you don’t really have to manage any of that as long as your overridden methods call the super class versions. super.initialize(), etc.

pspeed said:
if initialize() sets initialized to true... then you should be able to run it in a debugger and see that when isInitialized() is called it is returning that value. Or put a println or a log or something in there. There really shouldn't be any magic happening.

regarding your own isInitialized() I just thought it was odd to check if your application is initialized in simpleInit(). It either always will be or always won't be... but it's pretty odd.


I get what you're saying, thanks for the response. I'm going to tweak a little more and hope it all works out. :)