Asked — Edited
Resolved Resolved by JustinRatliff!

Executing Functions At Certain Times Of The Day

Depending on the time of the day, I want my robot to do one thing or a different thing. I cant figure the logic out to make something like below to happen.

I am hoping someone can give me some hints.

Here is my script

If ($time > "9:30:00" and $time "16:00"00" and $time < "09:30:00") print("to the other thing") endif

Thanks in advance.


ARC Pro

Upgrade to ARC Pro

Get access to the latest features and updates before they're released. You'll have everything that's needed to unleash your robot's potential!

#1  

Hi I think you can use this function:

WaitUntilTime( hour, minute ) Waits until the specified time. The script will stop at this command and not continue until the specified time. The time is declared in 24 hour format. Example: WaitUntilTime(17, 30)

Or you can try your way first by assigning the $time to another variable and comparing it using the 24 hour format as above

Hope this helps

regards

PRO
USA
#2  

Try this:


If ($hour&gt;17 and $minute&gt;30)
   Say(&quot;It's time for a Tea&quot;)
Endif

#3  

There are a few things syntax-wise wrong:


If ($time &gt; &quot;9:30:00&quot; and $time &quot;16:00&quot;00&quot; and $time &lt; &quot;09:30:00&quot;)
                               |      |   |                      |
                            Missing   |   \______________________/ 
                            Operator  |               |
                                      |      Needs to be removed
                                      |
                               Should be a colon

Like this:
If ($time &gt; &quot;9:30:00&quot; and $time &lt; &quot;16:00:00&quot;)             

I don't think you can compare the times like that either. I'll look into it though.

#4  

This is a bit complex but it will do what you want using the method you showed. What it does is convert the time strings to numbers by simply removing the colons. Then the comparison compares those numbers to the current time (also converted to a number). Be sure to always put in all 3 numbers. Each can be one or 2 digits as needed.


$StartTime =&quot;9:30:00&quot;
$EndTime   =&quot;16:30:00&quot;
Goto(ConvertTimesToNumbers)

   #Now compare the numbers
If($TheTime &gt; $StartTime and $TheTime &lt; $EndTime)
  print(&quot;to the other thing&quot;)
endif

Goto(TheExit)

:ConvertTimesToNumbers
   #Convert to numbers by removing the colons.
$StartTime =Split($StartTime,&quot;:&quot;,0)+Split($StartTime,&quot;:&quot;,1)+Split($StartTime+&quot;:&quot;,&quot;:&quot;,2)
$EndTime   =Split($EndTime,&quot;:&quot;,0)+Split($EndTime,&quot;:&quot;,1)+Split($EndTime+&quot;:&quot;,&quot;:&quot;,2)
$TheTime   =Split($Time,&quot;:&quot;,0)+Split($Time,&quot;:&quot;,1)+Split($Time+&quot;:&quot;,&quot;:&quot;,2)
Return()

:TheExit

If you wanted to dispense with the ConvertTimesToNumbers Goto routine, you could put the times in as numbers by leaving out the colons yourself. For example: "9:30:00" would be "93000"

The only thing that would still need converting would be the current time. If you did it that way the code could be:


$TheTime =Split($Time,&quot;:&quot;,0)+Split($Time,&quot;:&quot;,1)+Split($Time+&quot;:&quot;,&quot;:&quot;,2)

If($TheTime &gt; 93000 and $TheTime &lt; 163000)
  print(&quot;to the other thing&quot;)
endif

#5  

My 2 cents here, I like PTP's code example. Similarly, here is how I kick off or don't kick off an exercise reminder from my int script. It only kicks off between 8am and 9pm.


If ($hour &gt; 7 and $hour &lt; 22)
#do you action here
EndIf

PRO
USA
#6  

Thanks to everyone. Sometimes I just over think things.