Author Topic: [Resource] Calling schedules at a different time  (Read 1943 times)

This is to help call schedules at a different time, or you can just make them be called at a specific time.

void addToSchedule(
   string type - Can by anything, but when you release the schedules, it goes by this type.
   string function - The function, example: talk
   int milliseconds - In milliseconds, when do you want the function to be called after the release?
   string[0,15] type - Goes up to 15 args, probably. These are the arguments you can put for the function.
)

void releaseSchedules(
   string type - Releases all schedules by their type when they were added to the schedule list.
)

void clearSchedules(
   string type - Clears and cancels all schedules by their type when they were added to the schedule list.
)

Here are some examples

addToSchedule("test","talk",300,"testing 1 2 3");
addToSchedule("test","talk",1000,"hi! i'm testing..!");
addToSchedule("test","talk",1500,"yes! i'm testing..!");
addToSchedule("test","talk",2000,"yeah! i'm really testing..!");
releaseSchedules("test");


The code is here.
Code: [Select]
//Remember this
//Each global var, there will be a tab in between
//  $Schedules::All_[%num] = %type %func %ms %arg[0,15]
// or
//  $Schedules::Type_[%num] = %func %ms %arg[0,15]
function releaseSchedules(%type)
{
if($Schedules_["Total",%type] <= 0)
{
error("You cannot release empty schedules.");
return;
}
if(!strLen(%type)) %type = "ALL";
cancel($ClearSch);
if(%type $= "ALL")
{
    for(%i=0;%i<$Schedules_["Total",%type];%i++)
    {
    %main = $Schedules_[%type,%i];
    %main = strReplace(%main,"\t","" TAB "");
    //echo("Detected schedule: " NL %main);
    %func = getField(%main,1);
    %ms = getField(%main,2);
    if(%func !$= "")
    {
%crap = "";
    for(%a=3;%a<17;%a++)
    {
    %str = getField(%main,%a) @ ", ";
    if(%str !$= ", ") %crap = %crap @ "\"" @ %str @ "\"";
    }
    if(%crap !$= "")
    {
    %stuff = getSubStr(%crap,strLen(%crap)-4,4);
    %crap = getSubStr(%crap,0,strLen(%crap)-4) @ strReplace(%stuff,", ","");
    }
    $Schedule_["ALL",%i] = schedule(%ms,0,eval,%func @ "(" @ %crap @ ");");
    if(%ms > %bestMS) %bestMS = %ms;
    }
    $Schedule_["Total",%type]++;
    }
    }
    else
    {
    //echo("Found " @ $Schedules_["Total",%type] @ " schedules to order.");
    for(%i=0;%i<$Schedules_["Total",%type];%i++)
    {
    %main = $Schedules_[%type,%i];
    %main = strReplace(%main,"\t","" TAB "");
    //echo(" -> Detected schedule: " NL %main);
    %func = getField(%main,0);
    %ms = getField(%main,1);
    if(%func !$= "")
    {
        %crap = "";
    for(%a=2;%a<17;%a++)
    {
    %str = getField(%main,%a) @ ", ";
    if(%str !$= ", ") %crap = %crap @ "\"" @ %str @ "\"";
    }
    if(%crap !$= "")
    {
    %stuff = getSubStr(%crap,strLen(%crap)-4,4);
    %crap = getSubStr(%crap,0,strLen(%crap)-4) @ strReplace(%stuff,", ","");
    }
    $Schedule_[%type,%i] = schedule(%ms,0,eval,%func @ "(" @ %crap @ ");");
    if(%ms > %bestMS) %bestMS = %ms;
    }
    $Schedule_["Total",%type]++;
    }
    }
    $ClearSch = schedule(%bestMS,0,clearSchedules,%type);
}

//If %type is blank all holding schedules will be deleted and canceled
function clearSchedules(%type)
{
if($Schedules_["Total",%type] <= 0)
{
error("You cannot cancel empty schedules.");
return;
}
if(!strLen(%type)) %type = "ALL";
if($Schedule_["Total",%type] > 0)
{
for(%i=0;%i<$Schedule_["Total",%type];%i++)
    cancel($Schedule_[%type,%i]);
    }
deleteVariables("$Schedule_" @ %type @ "*");
deleteVariables("$Schedules_" @ %type @ "*");
$Schedules_["Total",%type] = 0;
$Schedule_["Total",%type] = 0;
}

function addToSchedule(%type,%func,%ms,%arg0,%arg1,%arg2,%arg3,%arg4,%arg5,%arg6,%arg7,%arg8,%arg9,%arg10,%arg11,%arg12,%arg13,%arg14,%arg15)
{
if(!strLen(%type)) %type = "ALL";
for(%i=0;%i<15;%i++)
%args = %args TAB %arg[%i];
%args = trim(%args);
if(%type $= "all") $Schedules_["ALL",$Schedules_["Total",%type]] = %type TAB %func TAB %ms TAB %args;
else $Schedules_[%type,$Schedules_["Total",%type]] = %func TAB %ms TAB %args;
    $Schedules_["Total",%type]++;
}
« Last Edit: December 06, 2014, 05:39:37 PM by Advanced Bot »

Nevermind, figured it out. The variable %crap was not cleared every time a schedule was planned to be executed.

Basically it kept evaling a bigger part of the variable every time a schedule was planned to be executed, which was a cluster forget inside the variable.
« Last Edit: December 06, 2014, 08:18:41 AM by Advanced Bot »

This seems interesting, but I don't see why you would ever need it.. Care to explain?

This seems interesting, but I don't see why you would ever need it.. Care to explain?

its so you can execute a function after a certain amount of time, while still keeping the flow of the script

its so you can execute a function after a certain amount of time, while still keeping the flow of the script

But that's exactly the same as a regular schedule. How is this different? The type thing is nice, being able to group schedules together, but I rarely need to have multiple schedules going at once.
« Last Edit: December 06, 2014, 12:58:15 PM by boodals 2 »

But that's exactly the same as a regular schedule. How is this different? The type thing is nice, being able to group schedules together, but I rarely need to have multiple schedules going at once.

oh sorry i was talking about the regular schedule function.

visolator's schedule basically lets you do multiple schedules at once under the same name.
this is so you can stop them all at once and so on.

Nice, though it seems like you over-complicated it a bit. I've added it to the coding resources thread.

Nice, though it seems like you over-complicated it a bit. I've added it to the coding resources thread.
Yeah.

I've updated the code a tiny bit for the variable again.