Server Help

Bot Questions - timer.scheduleAtFixedRate won't stop

BDwinsAlt - Sat Oct 29, 2005 8:59 pm
Post subject: timer.scheduleAtFixedRate won't stop
Well when i type !flags on it schedules my bot to send *flags every 10 minutes. The only problem if when i type !flags off, it doesn't turn the timertask off.

I tried:

timer.cancel();
task.cancel();
timer = null;
boolean cancel;

nothing turns this fixed rate off. How do i make it go away?

Code: Show/Hide

TimerTask task = new TimerTask(){
public void run(){
m_botAction.sendUnfilteredPublicMessage("*flags");
}
};
if( message.equals( "on" ) ){
tt.scheduleAtFixedRate(task, initialDelay, period);
flagStatus = on;
m_botAction.sendPrivateMessage( name, "Flag Announcing is ON" );
} else if( message.equals("off" ) ){
m_botAction.sendPrivateMessage( name, "Flag announcing off." );
      running=false;
      tt.cancel();
tt=null;
boolean cancel;
    flagStatus = off;
    }
[/code]
Purge - Sat Oct 29, 2005 9:09 pm
Post subject:
You sure you declared TimerTask() correctly?

I'd imagine something like this:
Code: Show/Hide
timertask = new TimerTask();


Then again, Java is evil. sa_tongue.gif
BDwinsAlt - Sat Oct 29, 2005 9:14 pm
Post subject:
Nope icon_sad.gif
D1st0rt - Sat Oct 29, 2005 9:18 pm
Post subject:
You don't actually have task.cancel(); in that block of code, which should do it. If not, you can use m_botAction.cancelTasks();

Your other option is to keep the task running and then just put a boolean flag within the task

Code: Show/Hide
TimerTask task = new TimerTask()
{
    public void run()
    {
        if(announceFlags)
            m_botAction.sendUnfilteredPublicMessage("*flags");
    }
};

BDwinsAlt - Sat Oct 29, 2005 9:25 pm
Post subject:
Didn't work. This is what i have...

Code: Show/Hide

public void flags(String name, String message){
  if(oplist.isSmod(name)){
Timer tt = new Timer();
int initialDelay = 5000;   // start after 5 seconds
int period = 600000;        // repeat every 10 minutes
TimerTask task = new TimerTask(){
public void run(){
m_botAction.sendUnfilteredPublicMessage("*flags");
}
};
if( message.equals( "on" ) ){
tt.scheduleAtFixedRate(task, initialDelay, period);
flagStatus = on;
m_botAction.sendPrivateMessage( name, "Flag Announcing is ON" );
} else if( message.equals("off" ) ){
m_botAction.sendPrivateMessage( name, "Flag announcing off." );
tt.cancel();
m_botAction.cancelTasks();
    flagStatus = off;
}
}
}

BDwinsAlt - Sat Oct 29, 2005 9:25 pm
Post subject:
lemme try ur supplied code 1 sec...
BDwinsAlt - Sat Oct 29, 2005 9:27 pm
Post subject:
I tried:

if(flagStatus == off){}
else
m_botAction.sendUnfilteredPublicMessage( "*flags" );
but when they type !flags on again it sets another timer and it runs 2 timers...
D1st0rt - Sat Oct 29, 2005 9:32 pm
Post subject:
Yeah, thats why you'd have to change the code of the !flags command to just change the boolean

Look at the code for bshipbot's night mode to see an example
BDwinsAlt - Sat Oct 29, 2005 9:34 pm
Post subject:
What do u suggest? icon_rolleyes.gif
D1st0rt - Sat Oct 29, 2005 9:35 pm
Post subject:
I edited not fast enough tongue.gif
BDwinsAlt - Sat Oct 29, 2005 9:37 pm
Post subject:
Thank You so much, ill try it.

icon_lol.gif icon_lol.gif icon_lol.gif icon_lol.gif icon_lol.gif icon_lol.gif icon_lol.gif
BDwinsAlt - Sat Oct 29, 2005 9:53 pm
Post subject:
I got it! You sexy hooker. icon_biggrin.gif
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group