Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
noname@wilke.me
Newbie


Joined: 23 Jul 2018
Posts: 9

PostPosted: 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
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 3836
Location: Pensacola, FL, USA

PostPosted: 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.
_________________
Windows 10 Home Premium 64-bit
AMD Phenom II x6 1055T 2.8GHz 16GB
CMUD Pro v3.34
Reply with quote
noname@wilke.me
Newbie


Joined: 23 Jul 2018
Posts: 9

PostPosted: 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
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 3836
Location: Pensacola, FL, USA

PostPosted: Sat Nov 24, 2018 2:34 pm   
 
#LOCAL $total
#FORALL @stringlist {$total=($total+%i)}
#PRINT Average is (%float($total)/%numitems(@stringlist))
_________________
Windows 10 Home Premium 64-bit
AMD Phenom II x6 1055T 2.8GHz 16GB
CMUD Pro v3.34
Reply with quote
noname@wilke.me
Newbie


Joined: 23 Jul 2018
Posts: 9

PostPosted: 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
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net