Home AMX User Forum NetLinx Studio

Specific time to trigger a channel

Dear,

Could anyone tell me how to do the following or any keyword that I can search in the forum?
I have tried time, clock or trigger, but fail, thanks all!

1. From monday to friday, it trigger morning function at 9am, lunch function at 1pm and night function at 6
2. Sat and sunday it only trigger morning and lunch function

does it mean i need to get time and date from master? in channel event or in define program?

Comments

  • JohnMichnrJohnMichnr Posts: 279
    The way I do it ( I'm sure there will be other wiser replies)

    you can use the TIME command in Define Program to do something at a specific time:
    DEFINE_PROGRAM
    
    if(TIME='09:00:00')
    {
        //do somthing here
    }
    

    note that you will want to put some other qualifyer in the if statement as the condition 09:00:00 will occur many times in define program depending on how fast teh define_program section is running.

    There is the DAY command as well that will return the day of the week , but a better use would be the DAY_OF_WEEK command. That returns a number
    DEFINE_PROGRAM
    
    stack_var sinteger sDay
    sDay = DAY_OF_WEEK (DATE)
    
    //do time 9:00
    //do time 1:00
    if( sDay = 1 || sDay=7)
    {
      //do time 6:00
    }
    
    
  • viningvining Posts: 4,368
    Make sure you put a wait 10 before the statement so that it only executes once. Otherwise during single second where if(TIME='09:00:00') will evaluates as true you could firesd off that code a couple hundred of times.
    if(TIME='09:00:00')
         {
         wait 10
    	  //do somthing here
         }
    

    I would also add a local var in the code below to keep that statement from executing more than once
    DEFINE_PROGRAM
    
    stack_var sinteger sDay
    local_var integer nRunOnce ;
    
    sDay = DAY_OF_WEEK (DATE)
    
    //do time 9:00
    //do time 1:00
    if(sDay = 1 || sDay=7)
         {
         if(nRunOnce != sDay)
    	  {
    	  nRunOnce = sDay ;
    	  //do time 6:00
    	  }
         }
    
  • I had an idea about this also. I think it's better (and probably more efficient) to do a timeline to run every second. In the timeline, check if it's 09:00:00 and if true, do the thing you want.
  • a_riot42a_riot42 Posts: 1,624
    JohnMichnr wrote: »
    DEFINE_PROGRAM
    
    if(TIME='09:00:00')
    {
        //do somthing here
    }
    

    I don't think that will work. I think you have to use compare_string.
    Paul
  • JohnMichnrJohnMichnr Posts: 279
    a_riot42 wrote: »
    I don't think that will work. I think you have to use compare_string.
    Paul

    I've used that since the dos days with no problem. The string handling will equat that to a true statement for as long as the clock is at 09:00:00. but you could use a compare as well. Never tried it.

    Timeline - overall is it really that much more effecient. I thought timelines added a bt of overhead.
  • ericmedleyericmedley Posts: 4,177
    JohnMichnr wrote: »
    I've used that since the dos days with no problem. The string handling will equat that to a true statement for as long as the clock is at 09:00:00. but you could use a compare as well. Never tried it.

    Timeline - overall is it really that much more effecient. I thought timelines added a bt of overhead.

    I also think there's a relatively small limiit to the number of timelines you can run simultaneiously. I think it's something like 15.

    And also also, I think a simple comparison is easiest.

    Here's what I'd do.
    DEFINE_VARIABLE
    
    volatile integer nflag
    
    DEFINE_PROGRAM
    
    if(!nflag and TIME='09:00:00')
    {
    nflag=1
    begin_world_takeover(minions_count)
    wait 15
      {
      nflag=0 // reset for next time
      }
    }
    
    
  • JohnMichnrJohnMichnr Posts: 279
    ericmedley wrote: »
    I also think there's a relatively small limiit to the number of timelines you can run simultaneiously. I think it's something like 15.

    Really - I had not heard that before - is that documented somewhere that I have never read?
  • kbeattyAMXkbeattyAMX Posts: 358
    Or you could do...
    define_program
    
    sDay = DAY_OF_WEEK (DATE)
    
    wait 10 'oneSecWT'
    {
      if ((time = '18:00:00') and ((sDay <> 1) or (sDay <> 7)))
      {
        //do the event
      }
       if (time = '09:00:00') 
      {
        //do the event
      }
      if (time = '13:00:00') 
      {
        //do the event
      }
    }
    
    

    It should only trigger once.
  • ericmedleyericmedley Posts: 4,177
    JohnMichnr wrote: »
    Really - I had not heard that before - is that documented somewhere that I have never read?


    I think I heard it in ProgIII (part deux) last summer. I don't remember for sure. My information is suspect at best. I jsut seem to remember the number thinking at the time, "Boy, I'd better be careful on how many timelines I may be running simultaneiously" and also thinking what would the result be of trying to run over the limit.

    Maybe when I get to Prog III (Part tre') this summer I'll make a point to ask. :D
  • Joe HebertJoe Hebert Posts: 2,159
    ericmedley wrote:
    I also think there's a relatively small limiit to the number of timelines you can run simultaneiously. I think it's something like 15.
    JohnMichnr wrote:
    Really - I had not heard that before - is that documented somewhere that I have never read?

    I never heard or read anything like that before either.
    ericmedley wrote:
    My information is suspect at best.

    You said it, not me. :)

    I just did a quick test with 100 simultaneous repeating timelines and I had no problems.
    If there is a limit it appears to be way more than 15.
  • Spire_JeffSpire_Jeff Posts: 1,917
    Joe Hebert wrote: »
    If there is a limit it appears to be way more than 15.

    Well, there is definitely a limit of 4,294,967,295. This is because the ID is of type long.

    Now, what if I need more that 4.295 billion timelimes???? :)

    Jeff
Sign In or Register to comment.