${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 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 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()"/>

and MyStartScreen.java part:

int score;
public void finishGame(int score)
    this.score = score;

public int scoreGame()
    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.


Maybe this is of any help:


1 Like

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

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