[SOLVED] Buttons not working with Nifty XML

I am using nifty XML for my start screen in my game. And I’ve been heavily using the wiki to learn how to use Nifty, but when I run the code, the starting screen shows however the buttons don’t work. I am aware there are similar topics to this on the forums but none of them worked for me.

My XML:
image

My Java: (I called the nifty in SimpleInitApp)


The error message it seems to give me is: WARNING: Could not extract method from [startMusic].

Of course if those were not enough I will upload more pictures.
Thanks for the help!

1 Like

It’s been awhile since I worked with Nifty at this level, but I think startGame() needs to be a method of your screen controller, not your application.

As in a seperate screen controller file like in the wiki? Because in my project as you might see, I set up my screen controller in Main.java

1 Like

The images you posted are cropped; I can’t see enough of your code to decide whether Main.java is your screen controller.

It’s not difficult to paste source code into this Forum. Just put triple backticks (```) before and after the code.

Do I need to simple post the simpleInitApp code? Or do I need to post most of what I have?

Also Im doing Nifty because its mostly the last thing left for me to try for a working gui, I don’t know anything else. But if you know something easier, let me know.

It’s up to you. How much help do you want? You need to supply an amount of information proportional to the help you need.

Somewhere in your code, you need to declare a screen-controller class. From the XML fragment you shared, it looks like it should be named mygame.Main. Does your mygame.Main class implement de.lessvoid.nifty.screen.ScreenController? (I can’t tell from the cropped images you provided.)

A possible problem is that your startGame() method doesn’t take any arguments. To be invoked from the XML and receive a passed value, I think the method needs a single String argument.

If you haven’t already, you should read the Nifty Manual. It’s slightly out of date, but it explains what a screen controller is (page 26 et seq) and how to pass a String to a callback method (page 72).

https://github.com/nifty-gui/nifty-gui/blob/1.4/nifty-core/manual/nifty-gui-the-manual-1.3.2.pdf

Ive read it and nothing changed

Yea, Ive done all of that, but still nothing. I dunno, but should I just try Lemur? I dont have experience with it though so Ill let you say if its good or not.

From all I’ve heard, Lemur is fine. However, I’ve never used it.

Try declaring your callback like so:

public void startGame(String hud) {
   setupKeys();

Awsome! Its finally now working. Thanks for your help! :slightly_smiling_face:

1 Like