NiftyGUI use a variable from SimpleApplication in ScreenController

Hello all, how can I use a variable that is in my SimpleApplication, in my ScreenController ?





[java]public class controller implements ScreenController {

private Nifty nifty;

private String mystr;



public controller(String arg0){

mystr = arg0;

}



public void action(){

System.out.println(mystr);





}



@Override

public void bind(Nifty arg0, Screen arg1) {

nifty = arg0;



}



@Override

public void onEndScreen() {





}



@Override

public void onStartScreen() {





}



}[/java]



I want to do it from my SimpleApplication, like this new controller(“Hello World !”);



How can I doing that ?

Exactly what you just wrote will work

There are two approaches:

  1. add a static variable somewhere to hold your application instance.
  2. don’t use the XML to instantiate your controller and instead instantiate them yourself and pass them to nifty when you load the XML… then they can have whatever state that you want to give them.



    Nifty will resolve the screens to controllers by class, using the ones you’ve provide to Nifty (Nifty 1.3 API)

Thank you.

Hope it helps. Making Nifty and JME play nice together was something took me a while to wrap my brain around. I actually ended up making all of my screen controllers also AppStates. Makes some things easier.