| View previous topic :: View next topic |
| Author |
Message |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Thu Jun 15, 2006 3:07 pm Post subject: Timer problem |
|
|
Hello!
I began to make a vote script. So maybe you can help me with a timer. In the following code I marked the line where I want to insert a timer.
| Code: | set votefile "scripts/vote.txt"
if {![file exists $votefile]} {
catch {close [open $votefile w]}
}
setudef flag vote
bind pub - !vote votescript
proc votescript {nick uhost hand chan arg} {
global votefile
channel set $chan +vote
putquick "PRIVMSG $chan :Vote initiated by $nick: $arg Type !poll yes and !poll no"
####Here a timer must be inserted. After 1 minute the bot should continue with the rest of this script.
channel set $chan -vote
set fp [open $votefile "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
set num 0
set randline [lindex $lines $num]
set yes [lindex $randline 0]
set no [lindex $randline 1]
putquick "PRIVMSG $chan :Voting period over. Results: Yes: $yes, No: $no"
set fd [open $::votefile r+]
while {![eof $fd]} {
lappend list [gets $fd]
}
set list [lreplace $list 0 0 [list 0 0]]
seek $fd 0
puts -nonewline $fd [join $list \n]
close $fd
} |
|
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Fri Jun 16, 2006 1:13 am Post subject: |
|
|
proc's are not to be put to sleep by timer; you should get your proc chores done as soon as possible and relinquish control to eggdrop, thus conforming to its event-driven I/O model
what you need to do is usually done by registering a timer which will invoke the specified proc after a short period of time _________________ connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code |
|
| Back to top |
|
 |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Fri Jun 16, 2006 9:24 am Post subject: |
|
|
| How can I invoke another proc after a special time? |
|
| Back to top |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Fri Jun 16, 2006 9:36 am Post subject: |
|
|
| darton wrote: | | How can I invoke another proc after a special time? |
timer, utimer (provided by eggdrop) or after (native tcl command) _________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Fri Jun 16, 2006 11:10 am Post subject: |
|
|
This here does not work.
| Code: | set votefile "scripts/vote.txt"
if {![file exists $votefile]} {
catch {close [open $votefile w]}
}
setudef flag vote
bind pub - !vote votescript
proc votescript {nick uhost hand chan arg} {
global votefile
channel set $chan +vote
putquick "PRIVMSG $chan :Vote initiated by $nick: $arg Type !poll yes and !poll no"
utimer 60 do:vote
}
proc do:vote {} {
channel set $chan -vote
set fp [open $votefile "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
set num 0
set randline [lindex $lines $num]
set yes [lindex $randline 0]
set no [lindex $randline 1]
putquick "PRIVMSG $chan :Voting period over. Results: Yes: $yes, No: $no"
set fd [open $::votefile r+]
while {![eof $fd]} {
lappend list [gets $fd]
}
set list [lreplace $list 0 0 [list 0 0]]
seek $fd 0
puts -nonewline $fd [join $list \n]
close $fd
} |
| Quote: | Tcl error in script for 'timer182':
can't read "chan": no such variable |
|
|
| Back to top |
|
 |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Fri Jun 16, 2006 11:23 am Post subject: |
|
|
| OK, I added the line "foreach chan [channels]" and it works now. Annoying that every variable is deleted by invoking another proc. |
|
| Back to top |
|
 |
|