mIRC Home    About    Download    Register    News    Help

Print Thread
$duration? #203605 21/08/08 10:01 AM
Joined: Jan 2008
Posts: 22
D
dassa Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2008
Posts: 22
Hi
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

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

Thanks

Re: $duration? [Re: dassa] #203606 21/08/08 10:13 AM
Joined: Jun 2008
Posts: 58
P
Pivo Offline
Babel fish
Offline
Babel fish
P
Joined: Jun 2008
Posts: 58
I would suggest saving $ctime and (as you mentioned) displaying the difference with $duration...

Re: $duration? [Re: dassa] #203607 21/08/08 11:05 AM
Joined: Jun 2008
Posts: 48
T
Typos Offline
Ameglian cow
Offline
Ameglian cow
T
Joined: Jun 2008
Posts: 48
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.
Code:
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
}


I've gone to look for myself. If I should return before I get back, please keep me here.
Re: $duration? [Re: Typos] #203608 21/08/08 11:44 AM
Joined: Jun 2008
Posts: 58
P
Pivo Offline
Babel fish
Offline
Babel fish
P
Joined: Jun 2008
Posts: 58
Correct me if I'm wrong, but isn't $ticks resetted with every Windows startup?

Re: $duration? [Re: Pivo] #203611 21/08/08 01:23 PM
Joined: Jun 2008
Posts: 48
T
Typos Offline
Ameglian cow
Offline
Ameglian cow
T
Joined: Jun 2008
Posts: 48
Directly from the always overlooked and forever under used mirc help file.
Quote:
$ctime
Returns total number of seconds elapsed since 00:00:00 GMT, January 1, 1970 based on your system time.

$ticks
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.


I've gone to look for myself. If I should return before I get back, please keep me here.
Re: $duration? [Re: dassa] #203613 21/08/08 01:57 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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:

Code:

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
}



-genius_at_work