I am working on a server/client based game using the KryoNet java library as well as slick. When the server class receives a connection from a client, it sends necessary startup information to the client, including what player number it is. One receiving this, the client starts slick and begins operating normally. The code for this is:
boolean started = false;
while(!started){
System.out.println(cs.playerNum);
if(cs.playerNum != -1){
cs.startSlick();
started = true;
}
}
The playerNum is set by another thread when the value is received from the server. For a while I could not get this to work (cs.startSlick() was never called), and eventually I got frustrated and began logging playerNum each time the loop ran. By adding System.out.println(cs.playerNum), the code began working, the loop would evaluate properly and slick would be started.
How is it possible that System.out.println does this? I have tried replacing it with other functions, and even other functions which take cs.playerNum as a parameter, but only when I specifically print cs.playerNum can I get the loop to work. If I need to include more source I can, but the issue seems to be directly here since I have tried replacing System.out.println with other functions to no success.