|
noname@wilke.me Newbie
Joined: 23 Jul 2018 Posts: 9
|
Posted: Fri Nov 23, 2018 3:48 pm
Time between events |
Hi!
I know this has been discussed before and I have studied the different threads containing similar issues without me getting anywhere closer to my needs.
I simply want to measure the time in seconds between two events, print the time between the events and also store the time in a variable which I can use for various purpose.
Example:
Event 1: You get a knife from the pack.
Event 2: You drop the knife.
I know this should be fairly simple but I can't get any of the tips in the other threads to work.
Best regards |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4702 Location: Pensacola, FL, USA
|
Posted: Fri Nov 23, 2018 4:15 pm |
There is no inbuilt feature to do this.
You can use %time (#HELP %time) to get the current time (up to the millisecond) and store it into a variable.
But it is up to the end user to use math in getting the difference.
I have never been fond of time math myself. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
noname@wilke.me Newbie
Joined: 23 Jul 2018 Posts: 9
|
Posted: Sat Nov 24, 2018 6:47 am |
Thanks, I got it to work. I want to share it if anyone else needs it. There are probably better ways to do this but it works for me.
At the first event I extract the time and store it in a variable:
Code: |
#VAR time_start %time(ss)*1000+%time(zz) |
I then do the same thing at the second event and then take the difference between the values and print it:
Code: |
#VAR time_end %time(ss)*1000+%time(zz) |
Code: |
#PRINT ----------- Time: (@time_end-@time_start) milliseconds ----------- |
I also wanted to store the difference in a variable:
Code: |
#VAR time_dif (@time_end-@time_start) |
AND I also store all the values in a string list:
Code: |
#ADDITEM time_dif_mean (@time_dif) |
And at the end I want the event variables to be empty again:
Code: |
#VAR time_end 0
#VAR time_start 0 |
This works great but I really want to be able to extract the mean value from the string list variable. I'm not really sure on how to do this, the only thing I found was the %average for Databases, but I'm not sure on how to put the time differences i calcuate in a database instead of a string list. Anyone know?
Best regards |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4702 Location: Pensacola, FL, USA
|
Posted: Sat Nov 24, 2018 2:34 pm |
#LOCAL $total
#FORALL @stringlist {$total=($total+%i)}
#PRINT Average is (%float($total)/%numitems(@stringlist)) |
|
_________________ Discord: Shalimarwildcat |
|
|
|
noname@wilke.me Newbie
Joined: 23 Jul 2018 Posts: 9
|
Posted: Sun Nov 25, 2018 7:17 am |
shalimar wrote: |
#LOCAL $total
#FORALL @stringlist {$total=($total+%i)}
#PRINT Average is (%float($total)/%numitems(@stringlist)) |
Thank you so much, works like a charm.
Cheers |
|
|
|
|
|