Reputation: 35
My Goal: Make one script wait .5 seconds, run, make another script wait .5 seconds, run.
The problem I am running into is that Timer.instance().clear(); makes the run() method only run once, on it's own it runs more than once. But, it also deletes Timer2 because it does not wait .5 seconds to run the code after the timer you scheduled (clear() removes all Timers/scheduled tasks). So, it ends up deleting the the Timer2 after .5 seconds.
Edit: Made a dumb error, I was not recognizing how the method was being called. I got it fixed :)
//Timer1
Timer.schedule(new Task(){
@Override
public void run() {
// \/ removes both Timer1 and Timer2
Timer.instance().clear();
}
}, .5f);
//Timer2
Timer.schedule(new Task(){
@Override
public void run() {
Timer.instance().clear();
}
}, 1f);
Upvotes: 0
Views: 1856
Reputation: 35
This works: "Make instance of timers: Timer timer1 = new Timer(); and Timer timer2 = new Timer(); then assign your schedules and code will run only once automatically. Like that: timer1.scheduleTask(....)" – aloupas
Upvotes: 1