I have a game that works and I want to write any high scores to a central server so people can compare their scores. The idea is just to have a thread that loops once a second and either does nothing (most of the time) or reads the current high scores or writes the players high score. The program on the web works fine but I’m having issues getting my daemon code to compile with static non static errors:
neptune.java:3951: error: cannot find symbol
try { this.sleep(2000); } catch (InterruptedException e) { ; }
^
symbol: method sleep(int)
neptune.java:3962: error: non-static method writeHighScores() cannot be referenced from a static context
neptune.writeHighScores( );
^
neptune.java:3966: error: non-static method isGameStillPlaying() cannot be referenced from a static context
} while( neptune.isGameStillPlaying() );
^
3 errors
My code is arranged like this:
public class neptune extends Panel implements Runnable, KeyListener {
int Score = 0;
...
public static void main(String[] args) {
neptune w = new neptune();
...
try {
WebIO webIoThread = w.new WebIO();
} catch (Exception e) { ; }
}
...
class WebIO implements Runnable{
public void run( ){
long timeLastAttempt = 0;
do {
try { this.sleep(2000); } catch (InterruptedException e) { ; }
// if failed to load high scores then try again
if ( neptune.ThreadAction == neptune.READ_SCORES
|| neptune.HighScoreScores[0] == 0
&& System.currentTimeMillis() - timeLastAttempt > 300000L ) {
timeLastAttempt = System.currentTimeMillis();
neptune.readHighScores( 0 );
neptune.ThreadAction = neptune.NO_ACTION;
} else if ( neptune.ThreadAction == neptune.WRITE_SCORES ) {
neptune.writeHighScores( );
neptune.ThreadAction = neptune.READ_SCORES;
}
} while( neptune.isGameStillPlaying() );
}
}
}
My apologies if I’ve included too much/too little. The problem is, if I start to change variables to static, then this soon snowballs into more static/non-static errors. I assume I’m missing something simple and just wondered if anyone could have a quick peek.
Many thanks
Mike