Author Topic: Calculate the elapsed time between two instances of {DATETICKS}  (Read 6720 times)

netkingcol

  • Newbie
  • *
  • Posts: 28
I want to calculate the elapsed time between two instances of the {DATETICKS} token, mainly because I'm too lazy to work with hours, minutes, and seconds.

I can see that {DATETICKS} is a long string, like: '636002250560258584', but I can't see how to manipulate it.

I've  tried expressions like: 

{EXP:SUBSTRING({DATETICKS},9,9)}

and

{EXP:SUBSTRING({TXT:MYVAR},9,9)} (after copying {DATETICKS} into another variable

but both of these approaches result in 'Expression error'. Can anyone see what's wrong with those expressions, or suggest a way to convert all or part of {DATETICKS} into a numeric value?



netkingcol

  • Newbie
  • *
  • Posts: 28
Re: Calculate the elapsed time between two instances of {DATETICKS}
« Reply #1 on: May 30, 2016, 10:33:30 AM »
Okay, I answered my own question. I need quotes around the token in the SUBSTRING call:

{EXP:SUBSTRING('{DATETICKS}',9,9)}

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4757
  • RTFM
Re: Calculate the elapsed time between two instances of {DATETICKS}
« Reply #2 on: May 30, 2016, 10:39:56 AM »
If you're just looking for the difference between two values, in ticks:

Code: [Select]
Set decimal [StartTime] value to the converted value of {DATETICKS}
Pause 1 second
Write '[Blue] {EXP:{DATETICKS} - {DEC:StartTime}}' to log

netkingcol

  • Newbie
  • *
  • Posts: 28
Re: Calculate the elapsed time between two instances of {DATETICKS}
« Reply #3 on: May 30, 2016, 10:59:45 AM »
Thanks again Pfeil, for holding my hand through these early days of Voice Attack development. After answering my own question, I used:

Code: [Select]
Set integer [IST_Start_Time] value to the converted value of {EXP:SUBSTRING('{DATETICKS}',8,4)}
Pause 10 seconds
Set integer [IST_Elapsed_Time] value to the converted value of {EXP:SUBSTRING('{DATETICKS}',8,4)}
Set integer [IST_Elapsed_Time] to [IST_Elapsed_Time] minus [{INT:IST_Start_Time}]
Write '[Purple] {INT:IST_Elapsed_Time}' to log


which gives the number of seconds (good enough for my purposes) between two time events. In the finished profile, the two DATETICKS observations will be in separate commands so the 'Start Time' variable is essential.

Your code, however, is more concise.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4757
  • RTFM
Re: Calculate the elapsed time between two instances of {DATETICKS}
« Reply #4 on: May 30, 2016, 12:15:58 PM »
Good that you've found a solution.

I'm inclined to (over)use "{EXP:}" for everything, but using actions when they're available helps with readability and ease of modification.