Nifty GUI will not call the void method on interact

Hi again :slight_smile:

I’ve recently ran into the problem of my play button not calling the void method it is supposed to when it is clicked. I’m trying to change app states into the gamePlayAppState, but there is no evidence that the method is ever called. I’m pretty sure that my XML code looks good, I’ve made sure the visibleToMouse=“true”, but regardless whenever the play button is clicked it doesn’t enter the startGame() method.

Here’s the XML:
[java]
<?xml version=“1.0” encoding=“UTF-8”?>
<nifty xmlns=“http://nifty-gui.sourceforge.net/nifty-1.3.xsd
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation=“http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd”>
<useStyles filename=“nifty-default-styles.xml” />
<useControls filename=“nifty-default-controls.xml” />
<registerSound id=“btnClickSound” filename=“Sounds/coin.wav” />

&lt;!-- Start Screen --&gt;
&lt;screen id="start" controller="smpp.experiment.game.StartScreenAppState"&gt;

	&lt;!-- This should add the background image --&gt;
	&lt;layer id="background" childLayout="center" width="100%" height="100%"&gt;
		&lt;image filename="Interface/FlightControlBackground.png"&gt;&lt;/image&gt;
	&lt;/layer&gt;

	&lt;layer id="foreground" childLayout="vertical"&gt;
		&lt;!-- Empty Spacer Panel to accomodate the background's header --&gt;
		&lt;panel id="panel_top" height="20%" width="100%" align="center"
			childLayout="center"&gt;
		&lt;/panel&gt;

		&lt;!-- Settings panel --&gt;
		&lt;panel id="panel_settings" height="15%" width="100%" align="center"
			childLayout="center"&gt;
			&lt;control name="button" font="aurulent-sans-16.fnt" label="Settings"
				id="SettingsButton" align="center" valign="center" visibleToMouse="true"&gt;
				&lt;interact onClick="gotoScreen(settings)" /&gt;
			&lt;/control&gt;
		&lt;/panel&gt;

		&lt;!-- Recalibrate Button --&gt;
		&lt;panel id="panel_recalibrate" height="15%" width="100%" align="center"
			childLayout="center"&gt;
			&lt;control name="button" label="Recalibrate" id="RecalibrationButton"
				align="center" valign="center" visibleToMouse="true"&gt;
				&lt;interact onClick="gotoScreen(calibrate)" /&gt;
			&lt;/control&gt;
		&lt;/panel&gt;
		&lt;!-- Play Button --&gt;
		&lt;panel id="panel_play" height="15%" width="100%" align="center"
			childLayout="center" visibleToMouse ="true"&gt;
			&lt;control name="button" font="aurulent-sans-16.fnt" label="Play!"
				id="PlayButton" align="center" valign="center" visibleToMouse="true"&gt;
				&lt;interact onClick="startGame()" /&gt;
			&lt;/control&gt;

		&lt;/panel&gt;
	&lt;/layer&gt;
&lt;/screen&gt;

</nifty>
[/java]

and the StartScreenAppState (which also acts as the startScreen controller)

[java]
public class StartScreenAppState extends AbstractAppState implements ScreenController {
/* AppState specific */
private SimpleApplication app;
private Camera cam;
private Node rootNode;
private AssetManager assetManager;
private InputManager inputManager;
private ViewPort guiViewPort;
private AudioRenderer audioRenderer;
private AppStateManager stateManager;
private boolean flagSoundEnabled = true;
private Listener listener;

private Node sceneNode;
private Nifty nifty;
public boolean isRunning;
StartScreenAppState start;
GamePlayAppState game;

@Override
public void initialize(AppStateManager stateManager, Application app) {
	super.initialize(stateManager, app);
	this.stateManager = stateManager;
	this.app = (SimpleApplication) app;
	this.cam = this.app.getCamera();
	this.rootNode = this.app.getRootNode();
	this.assetManager = this.app.getAssetManager();
	this.inputManager = this.app.getInputManager();
	this.guiViewPort = this.app.getGuiViewPort();
	this.audioRenderer = this.app.getAudioRenderer();
	this.app.getFlyByCamera().setEnabled(false);
	this.listener = this.app.getListener();

	//inputManager.clearMappings();

	initNifty();
}

public void bind(Nifty nifty, Screen screen) {
	System.out.println("bind( " + screen.getScreenId() + ")");
}

private boolean updateWinningScreen = false;

public void onStartScreen() {
	Screen s = nifty.getCurrentScreen();
	if(s.getScreenId().equals("completion")) {
		updateWinningScreen = true;
	}
}

public void onEndScreen() {
	Screen s = nifty.getCurrentScreen();
	if(s.getScreenId().equals("completion")) {
		updateWinningScreen = false;
	}
}

private NiftyJmeDisplay niftyDisplay;
private void initNifty() {
	niftyDisplay = new NiftyJmeDisplay(assetManager,
			inputManager,
			audioRenderer,
			guiViewPort);
	nifty = niftyDisplay.getNifty();
	nifty.fromXml("Interface/MainMenuLayout.xml", "start", this);
	nifty.addXml("Interface/SettingsScreen.xml");
	nifty.addXml("Interface/CalibrationScreen.xml");
	//nifty.addXml("Interface/inGameGui.xml");
	nifty.addXml("Interface/FeedbackScreen.xml");
	//nifty.addXml("Interface/CompletionScreen.xml");
	nifty.gotoScreen("start");

	// attach the nifty display to the gui view port as a processor
	guiViewPort.addProcessor(niftyDisplay);
}

public void startGame(Screen screen) {
	
	start = new StartScreenAppState();
	game = new GamePlayAppState();
	System.out.println("startGame() called... detaching start");
	stateManager.detach(start);
	System.out.println("Start screen detached");
	stateManager.attach(game);
	System.out.println("Game screen attached");

}

}
[java]

Any help would be much appreciated! Thanks :slight_smile:

Also, I changed startGame(Screen screen) to be just startGame(), right after I posted this. Sorry!

Figured it out.

What was the fix? I ran into the same issue… :confused:

I had changed the location of my screen controllers(put them in an appstate folder within the source) and hadn’t updated the path in the XML documents so it was using a default screen controller instead of the ones that had my custom methods in it. I’d check to make sure the paths that register the screen to the screen controller are correct.