I will try to explain my problem trough my simplified code.
public int timer_true;
public int timer_false;
public int timer_false1;
public int timer_false2;
...
public int points = 0;
public int points_true = 0;
public int points false1 = 0;
public int points false2 = 0;
...
Public class problem {
public void Presed(){
if (Button Start.Pressed){ //When the button Start is pressed I generate some random integers which I will use in my functions with timers
timer_true = (int) (Math.random() * (4 - 2+ 1)) + 2;
timer_false1 = (int) (Math.random() * (4 - 2+ 1)) + 2;
timer_false2 = (int) (Math.random() * (4 - 2+ 1)) + 2;
...
// After generating random timers I start the functions
true_method();
false_method1();
false_method2();
...
}
}
public void start_true() {
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
if(points>points_true){ // IF I DO THAT THE TIMER WILL STOP FOREVER, THE FUNCTION start_true() WILL NOT RUN
timer.cancel();
points_true++;
}
if (The right button is pressed){
points++;
timer.cancel(); //THIS IS NOT WORKING
restart_method(); //THIS METHOD DOES THE SAME AS THE METHOD Presed();
}
}
}
}, 0, true_method * 1000);
}
public void start_false() {
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
if(points>points_false){ THIS IS WORKING GREAT!!
timer.cancel();
points_false++;
}
if (The wring button is pressed){
System.out.print(You lost);
}
}
}
}, 0, true_method * 1000);
}
}
I will try to explain a little bitt. I have a game with timers. If a player chose the right solution I would like that al the timers reset and a now problem to solve is shown to the player. The problem is that the timers are reseted in the right way just for the timers of the wrong solutions.
I don't know how to reset the or stop or whatever the timer of the right solution.
Let's say that the first int timer is 2 (2 second) and I answer correct and the method generate a new timer which let's say is again 2 and then it wil work like the timer is set for 1 Second.
I hope you guys understood my problem.. if I was clear enough tell me, and I will try to re-explain my problem.
Thx to anyone who will try to help me!
Edited by Serialcek, 12 December 2011 - 07:21 AM.


Sign In
Create Account


Back to top









