This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

about timer

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

about timer

Post by ultralord »

hello

when i put:

timer 1 procname

sometimes doesnt run the proc in 1 minite but 50 seconds

or utimer 100 procname

sometimes runs on 50 seconds can i fix that?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

How do you know that?
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

Post by ultralord »

i see the proc's results.. and some messages
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Check to run timers are triggered by the "HOOK_MINUTELY" hook, which will occur whenever the minute-value has changed (usually at 00 seconds), and thus have an inaccuracy of less than a minute. If you need exactly 60 seconds, use utimer instead, as these timers are checked each second.
NML_375
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

Post by ultralord »

i use utimer.. but sometimes runs proc early.. ;/
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

utimers have an inaccuracy of less than a second, compared to timers which have an inaccuracy of less than a minute. If an utimer triggers much more early than this, it would usually indicate that the local clock on the system was advanced while the timer was "waiting".
NML_375
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

You could always set a var with [unixtime] at the beginning when the utimer is set, then within the proc set a different var with [unixtime] again and then subtract var2 from var1 and "if" it's 60 seconds, execute the rest of the proc, if not, calculate how many seconds remain and set a new utimer to run the proc again (which will calculate the time diff each time, etc.)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

That check would be pretty useless, as unixtime relies on the same timesource as HOOK_SECONDLY and timer-tracking. As such, the apparent time passed would always seem to be within one second of the desired time (or possibly longer, but never shorter).

The pretty much only reason why an utimer would start more than a second early, is as stated, that someone is playing around with the system-clock.
NML_375
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

Post by ultralord »

i have again that problem when i use eggdrop 1.6.9 version.. maybe the old that version have that problem? i want to run somethin on 5 minites and when i user timer 5 sometimes runs on ~3 minites etc.. and if i use utimer 300 (300 seconds) i have again the problem if the seconds is high.. the problem will be fixed if i use new version of eggdrop?


**i Use old version for something else because with new doesnt run :P if you know about timer tell me :) thanks
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

I made a small script as follows to test the accuracy of timers/utimers on my 1.6.19 bot :-

Code: Select all

# time.tcl
# syntax !time <integer> <minute||second>

bind PUB - !time pTimeTrigger

proc pTimeTrigger {nick uhost hand chan text} {
    set txt [split [string trim $text]]
    if {[llength $txt] == 2} {
        set number [lindex $txt 0]
        set type [lindex $txt 1]
        if {![string equal $number 0]} {
            if {[string is integer $number]} {
                switch -- $type {
                    minute {
                        pTimeStarted $number $type $chan
                        timer $number [list pTimeEnded $number $type $chan]
                    }
                    second {
                        pTimeStarted $number $type $chan
                        utimer $number [list pTimeEnded $number $type $chan]
                    }
                }
            }
        }
    }
    return 0
}

proc pTimeStarted {number type chan} {
    putserv "PRIVMSG $chan :Time Started ($number $type test) [ctime [unixtime]]"
    return 0
}

proc pTimeEnded {number type chan} {
    putserv "PRIVMSG $chan :Time Ended ($number $type test) [ctime [unixtime]]"
    return 0
}
Output is as follows :-

<@arfer> !time 1 minute
<@Baal> Time Started (1 minute test) Sat Jan 10 01:04:16 2009
<@Baal> Time Ended (1 minute test) Sat Jan 10 01:05:00 2009
<@arfer> !time 60 second
<@Baal> Time Started (60 second test) Sat Jan 10 01:05:55 2009
<@Baal> Time Ended (60 second test) Sat Jan 10 01:06:55 2009
<@arfer> !time 5 minute
<@Baal> Time Started (5 minute test) Sat Jan 10 01:07:10 2009
<@Baal> Time Ended (5 minute test) Sat Jan 10 01:12:00 2009
<@arfer> !time 300 second
<@Baal> Time Started (300 second test) Sat Jan 10 01:12:10 2009
<@Baal> Time Ended (300 second test) Sat Jan 10 01:17:09 2009

The results confirm above posts suggesting that minutely timers are only accurate to the nearest minute but secondly timers (utimers) are pretty much correct give or take a second.

However, I cannot see why you have a 5 minute timer triggering after approximately 3 minutes. This does not seem possible.

Feel free to use the script to run tests, that is if eggdrop 1.6.9 allows the included commands. Frankly, I think it is time you updated your bot version and accepted that your current scripts will no longer function.
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

Post by ultralord »

thnx for that test script my results..

17:10:16] <@Ultralord> !time 1 minute
[17:10:17] <@botnick> Time Started (1 minute test) Sat Jan 10 17:09:25 2009
[17:10:52] <@botnick> Time Ended (1 minute test) Sat Jan 10 17:10:00 2009
[17:11:04] <@Ultralord> !time 1 minute
[17:11:05] <@botnick> Time Started (1 minute test) Sat Jan 10 17:10:13 2009
[17:11:51] <@botnick> Time Ended (1 minute test) Sat Jan 10 17:11:00 2009
[17:12:04] <@Ultralord> !time 1 minute
[17:12:06] <@botnick> Time Started (1 minute test) Sat Jan 10 17:11:14 2009
[17:12:51] <@botnick> Time Ended (1 minute test) Sat Jan 10 17:12:00 2009
[17:13:23] <@botnick> Time Started (5 minute test) Sat Jan 10 17:12:31 2009
[17:17:51] <@botnick> Time Ended (5 minute test) Sat Jan 10 17:17:00 2009
[17:19:19] <@botnick> Time Started (5 minute test) Sat Jan 10 17:18:14 2009
[17:23:51] <@botnick> Time Ended (5 minute test) Sat Jan 10 17:23:00 2009

some tests.. sometimes like 1st bind i have problem.. is it possible the bot have count problem if the bot have lag? but i dont see any problem with any of my scripts and the scripts doesnt lag because i have some spam message and is ok..

thnx
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

The results shown above using my script would indicate that timer events are working as expected on your bot. ie. triggering to the nearest minute

What I know as lag is generally a time delay in the IRC network connection. This would cause a delay to occur before the channel output is seen, but I would not expect it to affect timer/utimer triggering.
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

Post by ultralord »

so how i can fix that to have correct time ? is it possible to fix that problem if i use the latest version of eggdrop ?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

As stated earlier, use the proper timer for the proper accuracy. timer gives you an accuracy to the minute, utimer gives you an accuracy to the second.

Also, you cannot script around lag, as that is not within the context of eggdrop scripting but network dependant.

The way I see it, there is nothing to fix (apart from using utimers when you need precision down to the second). Upgrading/downgrading your eggdrop will have no impact whatsoever on this issue.
NML_375
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

Post by ultralord »

ye i try the before script with 300 seconds and is ok same second.. i am going to user utimer 300 for timer 5 to see if it works better.

thnx
Post Reply