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.

Timer problem

Help for those learning Tcl or writing their own scripts.
Post Reply
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Timer problem

Post by darton »

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: Select all

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  
}
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

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: Select all

 tag when posting logs, code
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

How can I invoke another proc after a special time?
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

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"?
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

This here does not work.

Code: Select all

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  
}
Tcl error in script for 'timer182':
can't read "chan": no such variable
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

OK, I added the line "foreach chan [channels]" and it works now. Annoying that every variable is deleted by invoking another proc.
Post Reply