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
Somehow, the client doesn't switch the screen:
waitingForClients => start
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. :)
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)
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. :(
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:
Where it doesn't work:
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