Scheduled Tasks

Started by vcmptr, Mar 13, 2015, 06:03 PM

Previous topic - Next topic

vcmptr

I'm trying to create scheduled tasks. 
function tasks()
{
NewTimer("tasks",60000,1);
local now = date()
if(now.hour.tointeger() == 00)
{
SetWeather( 7 );
}
if(now.hour.tointeger() == 06)
{
OffCarLights();
}
if(now.hour.tointeger() == 18)
{
SetWeather( 5 );
}
if(now.hour.tointeger() == 20)
{
OpenCarLights();
}

}

But its not useful.  Example I can't schedule task from week to week. How can I make like Cron Job?
My English is not good.

Sebastian

I really don't understand what you mean, but I have a suggestion: learn to use switch function, instead of 9999 x if !

You should understand the difference by reading this:
Quote from: shadow.heekzLet's say there are 60 boxes, and an object, hidden in one of them.
If you will use "if" variant, will be like you are searching in every box until you find the object. (lot of effort and lost time)
But if you will use "switch" variant, will be like you know where is the object, and gonna search in the correct box. (much faster)

Also, here is an example:

switch( hour )
{
          case 0:
                    SetWeather( 7 );
                    break;
          case 6:
                    OffCarLights( );
                    break;
          case 18:
                    SetWeather( 5 );
                    break;
          default: break;
}

vcmptr

My fucking English... Thanks for the suggestion.
My English is not good.

aXXo

I believe you are trying to create an automatic system where a task is called on a weekly basis. The struggle is, that creating a timer is not feasible, because unfortunately our servers don't stay online for a week consistently.

Or maybe, you are trying to assign specific tasks to each day of the week. But even though the scripts can tell you the date, it can not detect(?) if the day is a Sunday or a Monday.

vcmptr

Quote from: aXXo on Mar 15, 2015, 10:28 AMI believe you are trying to create an automatic system where a task is called on a weekly basis. The struggle is, that creating a timer is not feasible, because unfortunately our servers don't stay online for a week consistently.

Or maybe, you are trying to assign specific tasks to each day of the week. But even though the scripts can tell you the date, it can not detect(?) if the day is a Sunday or a Monday.
Nice idea! Date function giving with index "wday". Thanks. :)
My English is not good.