Nifty.gotoScreen not working

Hey, :slight_smile:

I’m having some problems with the gotoScreen-method from NiftyGUI - In my game, a server and a client are started.

The client connects and the game is started - In both applications, the following code is called:

[java]System.out.println(nifty.getCurrentScreen().getScreenId() + " => " + screenID);

nifty.gotoScreen(screenID);

System.out.println(nifty.getCurrentScreen().getScreenId());[/java]



Note: This is inside a function which is called to switch screens, screenID is “start” in this case, the previous screenID of the nifty is “waitingForClients”.



The server gives the following output:

waitingForClients => start
start


Somehow, the client doesn't switch the screen:
waitingForClients => start
waitingForClients


I looked at every position I could imagine in my code and I think, there isn't much you can say about this without seeing more code.
I'm very sure, this error is due to different settings on client and server (Although they're running the exact same classes to display the GUI).

This topic is more the last hope for me - Maybe someone of you guys has an idea what would cause NiftyGUI to behave this way.
Perhaps I have to call some update method, so that the screen is changed before the System.out.println.

I hopy, someone of you has an idea. :)

Yours,
destro

EDIT: The two screens have different screen controllers, maybe this is important. But what confuses me, is that it works when I run it with the server but not on the client. :( (They have the same gui interface, the server is actually a subclass of the client, but doesn't override anything that's related to the engine/gui)

There is no chance you have a popup open on the client when you change screens is there?



Or you are issuing the change command off the render thread? (I’m not sure if that’s allowed or not but it’s something to check).

Or you are issuing the change command off the render thread? (I’m not sure if that’s allowed or not but it’s something to check).

That could be the reason, the change on the server side is done when the next frame is calculated (in the "main" jme thread) and the game sees, that there are enough players connected. It then sends a message to the clients, that the game has started - And this one is received and handled in another thread.

I'll look into this, thank you very much for your quick answer. :)

EDIT: The error still occurs when calling the screen change in the "main"/render thread of jME. :(

This is by the way how I’m creating the nifty - I’ve also tried the fromXML-method, but it’s the same result:

[java]private Nifty createNifty(String filePath){

NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(application.getAssetManager(), application.getInputManager(), application.getAudioRenderer(), application.getGuiViewPort());

application.getGuiViewPort().addProcessor(niftyDisplay);

Nifty nifty = niftyDisplay.getNifty();

nifty.addXml(filePath);

nifty.gotoScreen(“start”);

[…]

return nifty;

}[/java]

All I can suggest is eliminating differences until you find the one that makes it work…

Meanwhile, I found out a difference between server and client:

[java]nifty.getCurrentScreen().isRunning()[/java]



This is true at the server (where it works) and false at the client (where the screen doesn’t change) - Maybe this is the reason why nifty doesn’t go to the new screen.

Does anyone have an idea how to go sure, that the GUI is “running” or what could be the reason that it’s not running?

I experimented a little bit with the methods in the “Screen” class, but didn’t had success. :frowning:

The isRunning() method returns false both at the client/server directly after changing the screen, so I think, nifty takes some time to do the change - Therefore I checked if the update-method from the render-thread is called and it’s called a few times on both sides (it is called a few times).

At the one client, where it works, isRunning() returns suddenly true after some time (At this point, nifty changed the screen I think), but at the other client it stays false all the time and the screen isn’t changed.



Moreover, if I use the debugOutput-method of the Screen class, this shows up:



Where it works:

state [normal]


Where it doesn't work:
state [starting]


I googled for some sourcecode of nifty or other people that had problems with this, but didn't find anything. Has someone an idea, why nifty isn't "starting" the screen?


EDIT: Alright, I think the solution is very clear - Nifty takes a lot of time (not really much, but some time) to change a screen. The reason why it worked only at the first client (the server) but not on the second one is very simple.
The first one is started a few seconds earlier - Then I go back to the IDE and start another one. This time was enough for the first one to change the screen. But the second one has just connected to the first one and therefore, the game is starting. Unfortunately, it's impossible for nifty to change the screen in such little time.
My current solution: I just ask the GUI interface if it's ready for the game to perform an update of the view (isRunning ;)) - This causes a little delay after connecting until the screen changes, maybe half a second on the client, but it's understandable that the change couldn't be done fast since it's a very big screen nifty has to change to^^

Thanks all for your help, sometimes answers are so easy that you don't find the solutions until they lay directly in front of you. :D