Looping Schedules in TS

Author Topic: Looping Schedules in TS  (Read 799 times)

Im looking to make these chat lines repeat occasionally, and also delay in between each one.

1. Am I doing this right? Its my first time with schedules.

2. If a "loop" is what I'm looking for, how would I do it?


Quote

function delayannounce()

{

 schedule(1000, 0, "announce("You need to have 5 points to buy a gun! Use !buy for the menu!");");
 
 schedule(3000, 0, "announce("We hope you guys are having fun, and thanks for joining!");");

 schedule(5000, 0, "announce("Type !rtd and try your luck!");");

}

« Last Edit: January 16, 2013, 05:40:45 PM by TeeJay »

Not quite. First, %foo isn't defined. Second, announce isn't a method of any class. Third, you've got the syntax a bit wrong.

So, just remove %foo. all together. That leaves schedule(time, "function(parameters)"). This is still a bit wrong, you have to use a 0 as the second parameter and the function as the third, with the arguments for that function in following slots. So, correct would be schedule(time, 0, function, "message")

Not quite. First, %foo isn't defined. Second, announce isn't a method of any class. Third, you've got the syntax a bit wrong.

So, just remove %foo. all together. That leaves schedule(time, "function(parameters)"). This is still a bit wrong, you have to use a 0 as the second parameter and the function as the third, with the arguments for that function in following slots. So, correct would be schedule(time, 0, function, "message")

Edited the code, thanks.

2. If a "loop" is what I'm looking for, how would I do it?

I am now aware of how to, seeing as Yola told me over steam.

JazZ5109AI: function loop(%input) { schedule(500,0,loop,%input); //Do stuff here }
JazZ5109AI: Loop^

Code: [Select]
function loop(%input)
{
  if(PLEASEPUTACONDITIONHERE)
  {
    schedule(500,0,loop,%input);
    //Do stuff Here
  }
}
Don't hate me if I did something wrong.  I am on my iPhone.

Code: [Select]
$pref::server::loopftime = 15; //set the server pref 'loopftime' to 15

function loopingFunct(%e) {                                   //define the function 'loopingFunct' with arguments '%e'
 loopingCodeA();                                                   //run function A (not defined)
 loopingCodeB();                                                   //run function B (not defined)
 %rnd = getRandom(0, 100);                                 //define a random number and apply it to %rnd
 if(%e) $lFsched = schedule(1000, 0, oneSecDelayedLC, %rnd); //if '%e' is not zero or false, run oneSecDelayedLC
                                                                           //with the arguments %rnd after one second
 schedule($pref::server:loopftime * 1000, 0, loopingFunct, %e);
                                                                           //run loopingFunct again after the number of seconds in loopftime
}

function stopLoopingFunct() {
 cancel($lFsched);
}

function oneSecDelayedLC(%t) { //define function 'oneSecDelayedLC' with arguments '%t'
 talk("<color:00ccff>" @ %t); //say %t in cyan as Console in server chat
 echo(%t); //echo %t to the server console
}
« Last Edit: January 17, 2013, 04:01:19 PM by ThinkInvisible »

Don't forget to cancel the loop in the loop function