Author Topic: ading a time varible  (Read 4478 times)

shadowsol

  • Guest
ading a time varible
« on: January 16, 2017, 07:11:10 AM »
by that i mean a way to make an if then else statement using only time with no date so say i want something to hapen at 5:00 am i dont want to have to be locked in to that particular day just that particular time


EDIT by Pfeil: Functionality is available using tokens.
« Last Edit: April 18, 2020, 08:17:57 AM by Pfeil »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: ading a time varible
« Reply #1 on: January 16, 2017, 01:30:20 PM »
If all you're checking is the current time, you can do a text comparison:
Code: [Select]
Begin Text Compare : [{TIMEHOUR24}] Equals '05'
    Write '[Purple] It's 5 AM' to log
End Condition
I'm using 24-hour time for convenience, as you only need the number(plus I can't actually test AM/PM on my machine).

If you need minutes(colon added for convenience):
Code: [Select]
Begin Text Compare : [{TIMEHOUR24}:{TIMEMINUTE}] Equals '05:30'
    Write '[Purple] It's 5:30 AM' to log
End Condition

EDIT: "{TIMEHOUR24}" produces leading zeroes for single digit hours, heh.
« Last Edit: January 18, 2017, 04:09:53 PM by Pfeil »

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: ading a time varible
« Reply #2 on: January 16, 2017, 06:49:46 PM »
Those are good, Pfeil.

Also note you can pass in a datetime variable to any of the time tokens.

shadowsol

  • Guest
Re: ading a time varible
« Reply #3 on: January 18, 2017, 09:57:29 AM »
thanks gary sory it took me so long to get back i work 3ds and sleep most of my time if im not try to code/not break va
and fly in ed i was going to creat a code to make my pc play a cretin play list at a certain time  of day if you could help with this it would be most help full thanks

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: ading a time varible
« Reply #4 on: January 18, 2017, 04:22:16 PM »
The simple way:
Code: [Select]
Start Loop While : [{EXP:1=1}] Equals '1'
    Begin Text Compare : [{TIMEHOUR24}:{TIMEMINUTE}] Equals '00:06'
        Write '[Purple] {TIME}{TIMEAMPM}' to log
    End Condition
    Pause 60 seconds
End Loop
It'll check the time every 60 seconds, and execute whatever's inside the condition at that time. Because it waits 60 seconds, it also shouldn't execute the same thing multiple times within the same minute.


I'd started putting together a Cron-like command where it'd wait the amount of seconds until the next execution, but dealing with time manually is a pain in the rear.

Try it if you'd like, but I give no guarantees to it working properly:
Code: [Select]
Set small int (condition) [TriggerHour] value to 05
Set small int (condition) [TriggerMinute] value to 00
Start Loop While : [{EXP:1=1}] Equals '1'
    Set decimal [TimeToWait] value to 0
    Begin Text Compare : [{SMALL:TriggerHour}] Does Not Equal '{TIMEHOUR24}'
        Begin Text Compare : [{EXP: {TIMEHOUR24} < {SMALL:TriggerHour}}] Equals '1'
            Set decimal [TimeToWait] value to the converted value of {EXP: ({SMALL:TriggerHour} - {TIMEHOUR24}) * 3600}
        Else
            Set decimal [TimeToWait] value to the converted value of {EXP: ((24 - {TIMEHOUR24}) + {SMALL:TriggerHour}) * 3600}
        End Condition
    End Condition
    Begin Text Compare : [{SMALL:TriggerMinute}] Does Not Equal '{TIMEMINUTE}'
        Begin Text Compare : [{EXP: {TIMEMINUTE} < {SMALL:TriggerMinute}}] Equals '1'
            Set decimal [TimeToWait] to [TimeToWait] plus [{EXP: ({SMALL:TriggerMinute} - {TIMEMINUTE}) * 60}]
        Else
            Set decimal [TimeToWait] to [TimeToWait] plus [{EXP: ((60 - {TIMEMINUTE}) + {SMALL:TriggerMinute}) * 60}]
        End Condition
        Begin Decimal Compare : [TimeToWait] Is Less Than Or Equals 0
            Set decimal [TimeToWait] to [TimeToWait] plus 86400,00000
        End Condition
    End Condition
    Pause a variable number of seconds [TimeToWait]
    Play sound, 'C:\Windows\Media\Windows Logon Sound.wav'
    Pause 60 seconds
    Write '[Purple] Recalculation wait time' to log
End Loop
I think it may have issues with negative time, but I'm not sure. I've given up.

Frankly, you could just use the Windows Task Scheduler, which is intended for long-term stuff like this.