egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Timer problem

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Thu Jun 15, 2006 3:07 pm    Post subject: Timer problem Reply with quote

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
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Fri Jun 16, 2006 1:13 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Fri Jun 16, 2006 9:24 am    Post subject: Reply with quote

How can I invoke another proc after a special time?
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Fri Jun 16, 2006 9:36 am    Post subject: Reply with quote

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
View user's profile Send private message
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Fri Jun 16, 2006 11:10 am    Post subject: Reply with quote

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
View user's profile Send private message
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Fri Jun 16, 2006 11:23 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber