mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jun 2004
Posts: 6
Q
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Q
Joined: Jun 2004
Posts: 6
I have a script that does something at an exact time, every hour and half hour of the clock. What I have is
Code:
 alias hourclock { if ($asctime(nn:ss) == 00:00) || ($asctime(nn:ss) == 30:00) { msg #time It is now $asctime(dddd mmmm dd yyyy hh:nn:ss tt) -0500 UTC (EST).  (24 hour time is $asctime(HH:nn:ss) $+ ). Go to #time for time. } }  
and I do a /timer 0 1 hourclock
Well, it works most of the time, and when I say most, I mean that it doesn't work like once in 5 days. It is also inherently inaccurate. The timer checks every 1 second, so there is a maximum error of 1 second. I want the script to execute at the very beginning of the second. I observe that it sometimes happen between the 0th second and the 1st second. That is the nature of this script. So how do I make it so it happens at the exact start of the second, aka when the second hand is exactly on 12.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Getting something like that to run exactly on the second is not (realistically) possible, as there has to be time for the script to run, which is part of the reason it appears to run between 0 & 1 second.
The script might start at 0, but then it takes time for the script to run. You might be able to get it closer if you knew exactly how long it took for the script to run, and then started the script that much before the hour/half hour.

One problem in determining how long it takes for a script to run, is the fact that, unless this is the only script running on mIRC, and mIRC is the only program running on the computer, and it's impossible for anything else to run, you're not going to be able to guarantee that something else might not take up processing time on the computer, which, in turn, will cause the script to take longer to be started & executed.

Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
it has been explained in other threads on this forum, but timers and so on are just not accurate

a simple test would be these two aliases using $ticks and the millisecond timer
run it a few times and watch the decimal difference drift

it is what it is
Code:
timertest {
  set -u30 %starticks $ticks
  timertest -m 5 1000 timertest2 $!ticks 
}
timertest2 {
  echo -a . $calc(($ticks - %starticks) / 1000))
}

Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
I hope you know that messages to the server can take more than a minute to show up on other people's clients. If the network is really busy, badly managed or under attack, server lag can go way up. I can tell you that trying to play on a trivia chan on such a network is not fun: you only see the question after the time to answer it is up crazy

The only decent way to get an accurate time reading is using NTP (network time protocol). There are free clients around, it's even built into Windows XP, but it only checks every 5 days or so by default, so on my computer with a 2 sec/hour drift it's really not useful...

Joined: Jun 2004
Posts: 6
Q
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Q
Joined: Jun 2004
Posts: 6
yes, i use ntp, but all i care is that mirc does it at the exact moment. Is there a way to do it without timers? or with a more accurate timer?

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
alias hourclock {
  if ($1 != ontimer) {
    .timerhourclock.one.off $time($calc($ctime + 1800 - ($ctime % 1800))) 1 0 hourclock ontimer
    .timerhourclock $time($calc($ctime + 1800 - ($ctime % 1800))) 0 1800 hourclock ontimer
  }
  else {
    msg #time It is now $asctime(dddd mmmm dd yyyy hh:nn:00 tt) -0500 UTC (EST).  (24 hour time is $asctime(HH:nn:00) $+ ). Go to #time for time.
  }
}


usage /hourclock
Then just wait till the hour & half hour mark roles around!


Since timers are restricted to accuracy of mircs internal proformance loop whcih can be effected internally by other mirc activities and externally by other windows activities, you cant get exactly perfect time but its close (most of the time). So i suggest the code above, just dont show the seconds your at at all, and set them to zero, a bit of a cheat some might say, well I say this, who are you trying to impress anyway, sicne your sending this "exact" time out to a irc server and then back to other irc clients, you can expect LAG anyway, so when you say its "exactly" 12:00:00 where you are, well they dont see that for 1.234242 seconds so it isnt anymore anyway is it!

Joined: Nov 2005
Posts: 1
S
Mostly harmless
Offline
Mostly harmless
S
Joined: Nov 2005
Posts: 1
ex /timer 02:11 1 1 //echo -a $time
when 2:11 is the exact time you will echo $time wink


Sparkle/Ahmed
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
ex /timer 02:11 1 1 //echo -a $time
when 2:11 is the exact time you will echo $time wink


That goes off at 02:11:01 (assuming no external or internal delay) not 02:11

Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
To get a timer to activate as accurately as possible, the high-resolution switch can be used.

/timer -h 18:30 1 1 /echo -a $time

But just like everyone else has already mentioned, IRC is not designed for high-accuracy events. Even if a script is accurate to the millisecond, the lag over the internet destroys that accuracy.

-genius_at_work

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
A high resolution timer is unneeded for this. Its simply a matter of NOT telling it to delay for 1 second (or in your case 1 ms)

/timer -h 18:30 1 0 /echo -a $time


Link Copied to Clipboard