Nifty GUI Progress > update/variable

Hi all.

  1. I’m progressing NiftyGuiDemo and I’m trying to figure out how work writing (variable) to GUI. And i don’t understand why if i start “” => in “hud” screen score is set to basic “123” and if i start “” file > in same screen(hud) score work as it should (by method in controller). Everything seems be similar… both GUIs use same controller (

    Can you help me with understand it PLS.

  2. Another task > In topic

    I will need write score variable to GUI. Solution in this topic seems be like single “shot” (for variable which won’t change). It is true or can i use it for the changing variable like “score” is?

    THX for answers. I will be really glad…

    *sry for my english

AppStates ;).

I mean this parts:


control(new LabelBuilder(){{










public void update(float tpf) {

if (screen.getScreenId().equals("hud")) {

Element niftyElement = nifty.getCurrentScreen().findElementByName("score");

niftyElement.getRenderer(TextRenderer.class).setText(tpf*1000/10 + ""); // fake score




this do not work in my app

Your update code looks valid, I certainly do similar and it works. I’d do String.valueOf() not +"" though. I’m not sure if the compiler will be smart enough to do +"" without a stringbuilder.

Put a log statement in to make sure the code is getting called. Also keep in mind that tpf may well be the same each time so you might want to use an incrementing variable or something.

Finally i continue… BUT

But my code is doing error when i swith to empty screen(if i go to from menu to setup > it work). In my ScreenControler:


public void update(float tpf) {

if (screen.getScreenId().equals(“menu”)) {

Element niftyElement = nifty.getCurrentScreen().findElementByName(“textScoteALL”);

niftyElement.getRenderer(TextRenderer.class).setText("Score: " + score + " Top Score: " + topScore); //THIS LINE





IV 07, 2012 2:50:37 ODP. handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]


at mygame.MyScreenController.update(



at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(




Error show when i try close “menu” screen (change to empty screen). Before i did this code for update text everything work fine.

EDIT: I tryed move this code to some metod and update text only when is value “score” would change but seems that i can’t do it when screen(with this text) is not active…

And one more question:

What is better? > set screen by screencontroller or by nifty in my Main class (game).


startScreen.toScreen("gameOver");//screencontroller(my metod)[/java]

Without looking in detail at what you are doing I expect that if the screen isn’t empty then you can’t find the component in order to set the text as the element isn’t on the active screen at that time. Only try and update the text if the screen is active and when the screen is switched to then make sure it is updated to the correct value at that time.

Thx man. I fix this… I created method which i call after opened screen with text. Code will do only once and everything is fine. I don’t know why this solition i didn’t think faster.

One more thx…