mIRC Homepage


Posted By: dassa

$duration? - 21/08/08 10:01 AM

What is the best way to count time in days and minutes? For example say i want to add data to a hash table when i start mirc. Then when i resatrt mirc i want it to echo when the last time i started mirc in days and minutes format.

Code example

on *:start: {
hadd -m hashtable data
echo 4 -s You last opened mirc x days and z minutes ago.

Posted By: Pivo

Re: $duration? - 21/08/08 10:13 AM

I would suggest saving $ctime and (as you mentioned) displaying the difference with $duration...
Posted By: Typos

Re: $duration? - 21/08/08 11:05 AM

I made this using ticks instead of ctime and I also added a $replace to the $duration to make the output look better. I had the script make sure the item exists in the hash table before echoing so that it wont echo if its the first connection and the data doesnt exist yet.
I also have it check if the hash table exists and if not create it incase its the first connection.

Hope this helps.
On *:Connect:{
  if ($hget(LastConnected,Connected)) { echo 4 -s You last opened mirc $replace($duration($calc(($ticks - $hget(LastConnected,Connected)) / 1000)),min,$chr(32) $+ minute,sec,$chr(32) $+ second,hour,$chr(32) $+ hour,day,$chr(32) $+ day,week,$chr(32) $+ week,month,$chr(32) $+ month,year,$chr(32) $+ year) ago. }
  if (!$hget(LastConnected)) { hmake LastConnected }  
  hadd LastConnected Connected $ticks
Posted By: Pivo

Re: $duration? - 21/08/08 11:44 AM

Correct me if I'm wrong, but isn't $ticks resetted with every Windows startup?
Posted By: Typos

Re: $duration? - 21/08/08 01:23 PM

Directly from the always overlooked and forever under used mirc help file.
Returns total number of seconds elapsed since 00:00:00 GMT, January 1, 1970 based on your system time.

Returns the number of ticks since your operating system was first started.

So yeah but its still usefull for things like in my example. I figured since he was using a hash table he wasnt concerned with holding the data thru a reboot. Genius at work just submited a much better code than the one I came up with earlier if the op doesnt need to stick with the hash table.
Posted By: genius_at_work

Re: $duration? - 21/08/08 01:57 PM

Is there a specific reason that you want to add the data to a hash table instead of a global variable? If you use a hash table, you have to /hsave it when you exit mIRC and /hload it right when mIRC opens, or else the hash won't exist (hashes are destroyed when mIRC closes). The simplest way is to use a global variable, or an ini file. Example:


on *:START:{
  if (%stime) echo -a Last started mIRC $duration($calc($ctime - %stime)) ago.
  else echo -a No record of you starting mIRC before.
  set %stime $ctime

© 2020 mIRC Discussion Forums