${CALL.method()} doesn't work

I write a basic game with nifty gui by seeing nifty tutorial but I can’t get a int value from MyStartScreen. My xml screen part is:

<screen id="finish" controller="StormySpace.MyStartScreen">
   <layer id="foreground" childLayout="vertical" >
      <panel id="top" width="100%" height="40%" childLayout="center">
          <text text="GAME OVER" font="Interface/Fonts/Purisa.fnt" valign="bottom"  width="100%" height="100%" wrap="true"/>
      </panel>
      <panel id="mid" width="100%" height="30%" childLayout="center">
          <text text="Your Score: ${CALL.scoreGame()}" font="Interface/Fonts/Purisa.fnt" valign="top" width="100%" height="100%" wrap="true"/>
      </panel>
      <panel id="bottom" widht="100%" height="30%" align="center" childLayout="horizontal">
          <control name="button" label="Quit" id="QuitButton2" align="center" valign="center" visibleToMouse="true" >
              <interact onClick="quitGame()"/>
          </control>
      </panel>
  </layer>
</screen>

and MyStartScreen.java part:

int score;
public void finishGame(int score)
{    
    this.score = score;
    System.out.println(this.score);
    nifty.gotoScreen("finish");
}   


public int scoreGame()
{
    System.out.println(score);
    return score;
}

Everything is fine but just game never run scoreGame() methode. I see “Your Score: 0” on screen. I add println methods for controling and just first is running. Anybody help me?

The method does work. When the gui is initialized the method will be executed once and that’s it, because there is no other event which could call this method. Because of this you have to get your text element into code and refresh it from there.

2 Likes

Maybe this is of any help:

http://davidb.github.io/sandbox_wiki_jme/jme3/advanced/nifty_gui_scenarios.html

1 Like

Thanks guys. I solved by using Main.java class after assign an id to text field:

myStartScreen.finishGame();
Element niftyElement2 = nifty.getScreen("finish").findElementByName("yourscore");  
niftyElement2.getRenderer(TextRenderer.class).setText("Your Score: " + score);