mIRC Home    About    Download    Register    News    Help

Print Thread
#179369 22/06/07 02:34 AM
Joined: Jun 2007
Posts: 15
W
Pikka bird
OP Offline
Pikka bird
W
Joined: Jun 2007
Posts: 15

Code:
 dialog away2 {
  title "away system"
  size -1 -1 195 111
  text "reason¬", 1, 20 20 41 15
  edit "", 2, 66 18 110 20, autohs
  button "away", 3, 17 81 75 17
  text "interval¬", 5, 19 44 45 15
  edit "", 6, 66 42 63 20
  box "setup", 7, 5 -1 185 108
  text "hours", 8, 134 44 40 16
  button "cancel", 9, 103 81 75 17, cancel
  box "", 10, 7 65 183 8
}
alias awaysys { if (!%away) dialog -mod away2 away2 | if (%away) awayback }
;dialog events
on *:dialog:away2:init:0: {
  if (%away == on) {
    did -a $dname 2 %away.r
    did -a $dname 6 $calc(%away.timer * 60)
    did -b $dname 4
  }
}
on *:dialog:away2:sclick:3: {
  if (!$server) halt
  if (!$did(2).text) halt
  if (!$did(6).text) halt
  set %away.r $did(2).text
  set %away.timer $calc($did(away2,6).text * 60)
  set %away on
  set %left left; $time(h:nnt)
  ame now idle: %away.r %left
  .away %away.r
  .timeraway 0 $calc(%away.timer * 60) stillafk
  set %away.leave $ctime
  dialog -x away2 away2
}
alias awayback {
  %away.back = $dur($calc($ctime - %away.leave))
  .timeraway off
  if ($server) .away
  unset %away 
  if ($server) && ($chan(0)) ame has returned: %away.r %away.back
  unset %away.*
  unset %left
}
alias stillafk {
  %stillafk.dur = $dur($calc($ctime - %away.leave))
  ame still idle: %away.r elapsed: %stillafk.dur %left
}
alias dur {
  if ($1 < 60) { .return $round($1-,0) $+ s }
  else { return $replace($duration($1-),wk,w,secs,s,mins,m,hrs,h,days,d,wks,w,sec,s,min,m,hr,h,day,d) }
}


I set the timer for "1" hour and after 1 hour I get the following message:

weakness : still idle : afk again elapsed : 59m 59s left; 9:10p

instead of the time returning 60 minutes or 1 hour. Any ideas as to why ?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
the only thing that I can think of, after reviewing your code, is that it's taking more than 1/2 a second to process the aliases stillafk and dur. This can happen if you have more than one script trying to process at the same time (especially if you have lots of them).

Does this still happen if you try it with just this one script loaded?

Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
That's just something that happens from time to time. Timers aren't entirely accurate.

This is some results from typing //.timer 1 5 echo -ag * $!duration($calc($ctime - $ctime ))
* 4secs
* 5secs
* 5secs
* 4secs
* 5secs

Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
Originally Posted By: RusselB
This can happen if you have more than one script trying to process at the same time

Can't happen, mIRC is single threaded. Once a script is started no other script can be executed until the first is finished. wink
(Exceptions here include some uses of $com, $comcall, $dllcall)

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Yes, I worded that badly.
What I meant was something like:
Timer 1 runs Script B every 30 seconds
Script A starts at 15 seconds and takes 20 seconds to run
Since Script A is already running (15 seconds in) when Script B is supposed to run, then Script B won't run until Script A is done..5 seconds later

Weakness, one way of reducing the amount of discrepancy, if this is strictly being generated by the timer, is to use the -m switch, and use a millisecond timer. Note: these are harder on system resources, so I don't recommend them if the accuracy isn't needed/wanted or if you plan on using a lot of them running at about the same time.

Last edited by RusselB; 22/06/07 07:10 AM.
Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
Yeah, I too worded that badly.
It's not actually the timer that's inaccurate, once a timer is started it's pretty darned accurate. smile It's in the setting of the timer where this occurs.

It's hard for me to explain what i mean, but it seems if its XXX ms before/after a whole second then the timer will fire that second earlier or later.
Once it is set though, the delaytime is accurate enough. smile

Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Quote:

If you specify the -m or -h switch, this indicates that the interval delay is in milliseconds.



Note: The -h switch creates a high-resolution multimedia timer. This type of timer should only be used in critical timer situations since it uses system resources heavily.



The -d switch ensures that a timer and any subsequent timers using the -d switch are triggered in that order.


These switches for the /timer command may be useful.

-genius_at_work


Link Copied to Clipboard