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.

fix sintax commands utimer, after and vwait

Help for those learning Tcl or writing their own scripts.
Post Reply
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

fix sintax commands utimer, after and vwait

Post by juanamores »

What is the correct syntax for this line?

Code: Select all

utimer 5 {set modes [getchanmode $chan];putmsg $chan "Current modes: $modes"}
Error:can't read "chan": no such variable.

What is the correct syntax for this code?

Code: Select all

after 5000 { set modes [getchanmode $chan]  }
putmsg $chan "setting modes....."
vwait modes
putmsg $chan "current modes are $modes"
Error: can't wait for variable "modes": would wait forever"

Please, fix these errors, I read and read but I don´t understand.
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Re: fix sintax commands utimer, after and vwait

Post by willyw »

Here is some reading material that explains how to use timer and utimer like that.

http://web.archive.org/web/200702051134 ... cters.html

The part you want it about half way down, under:
The second golden rule of Tcl for eggdrop

I hope this helps.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

juanamores: Please show your entire script here, so we can see the context for where these few lines are being called.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

SpiKe^^ wrote:juanamores: Please show your entire script here, so we can see the context for where these few lines are being called.
After running 'newchanvite' command, BoT change channel modes, for the reasons explained in this post.
Slowly going correcting code to delete the modes set by the bot.
I only need to correct timers and vwait command syntax.

Code: Select all

bind pub o|o !addinvite pub:addinvite

proc pub:addinvite {n u h c t} {
###### I store channel modes in the variable modes1 #####   
    set modes1 [getchanmode $c]
###### Show values on channel ######
   putmsg $chan "The channel current modes are: $modes1"
##### Add mask to nick ($t)#####
   set t "$t[join !*@*]"
##### Consults if the nick is on the invite list Channel ($t)#####   
   if {![isinvite $t $chan]} {
     newchaninvite $chan $t invite 0 sticky
##### I add this timer for 5 seconds to allow time for the list to refresh (Has the correct syntax the next line, utimer command or need after command?)#####
     utimer 5 [list set modes2 [getchanmode $chan]]
 ##### HERE is where the problems begin, because the variable $modes2 is not yet set will by the timer 5 seconds!#####
####The code stop here, until $modes2 variable is not set, and then continue to the next line when variable $modes2 be set. ####
#### 
     vwait modes2 
putmsg $chan "Now the channel current modes are: $modes2"     
set large [string length $modes2]
     set x 0
     while  {$x < $large} {
         if {[string index $modes2 $x] in $modes1} == 0 {
          set modchange [string index $modes2 $x]
          pushmode $chan "-[join $modchange]"
          unset modchange
         }
     incr $x
     }
    putmsg $chan "$t has been added to the autoinvite database $c"
    return
   } else {
 putmsg $chan "$t is already in the autoinvite database $c"
     }
}
If I use the line:
utimer 5 [list set modes2 [getchanmode $chan]]
Or the line:
after 5000 {set modes2 [getchanmode $chan]}
Error:can't read "modes2": no such variable.

If I add as a line 1 of the proc:
global modes2
The bot is frozen and I have to kill eggdrop process from Windows Task Manager.

Something is wrong with timers compared with vwait command.
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

If you want to learn how to use the vwait command, I'm not going to address that. I don't recall ever using it myself.
I can speculate that it is blocking, so that nothing else can happen.
Since vwait comes into effect before the utimer expires and sets the var, it never happens. The result is a locked up bot.
But... that is just me speculating. Perhaps somebody else will come along that has used vwait, and can help you with that.

If you just want to get it working, and your goal is to introduce some delay, then how about another idea:

Code: Select all

... 
set modes2 [getchanmode $chan]
utimer 5 [list rest_of_commands $c $modes1 $modes2 $t]

proc rest_of_commands {chan modes1 modes2  t} {
... 
        commands go here
...
} 
Get the idea?
Just group the rest of the commands in a proc.
Use a utimer to call that proc.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

In your current process, you insist on calling the variable $chan...
putmsg $chan "The channel current modes are: $modes1"
...and at least 3 other times.

The variable $chan Does Not Exist, as you have named the channel var $c...
proc pub:addinvite {n u h c t} {
Calling a variable that does not exist will always result in a tcl error.

I'm with willyw on the whole vwait deal, nothing good can come from it:)

Beyond that, very little of that code will ever function at all.
You should be fixing the script that is causing your modes issue, and not trying to write a script to fix another broken script.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

[SOLVED]

Post by juanamores »

Tell you that I have solved the problem.
Very grateful to willyw and Spike ^^.

The idea of willyw, I invested because if the set modes2 [getchanmode $chan] command is executed before the timer,was not the result that I wanted, to wait 5sec and refresh the list and then take its value.

Regarding the comment Spike^^ related to chan, I had changed my code before and everything was the same.

The problem was discovered by testing the code in parts, to the point where the BoT froze.

The error was in the While, had 2 errors, one was a brace:
if {[string index $modes2 $x] in $modes1} == 0 {
The other most important mistake why the bot froze, was that the x variable is not increased in value.
Thus x always worth 0 (zero) and became infinite loop.

I managed to fix the increase in x variable, placing it at the beginning of the loop.
You may wonder but that makes x starts with a value of 1 instead of 0.
That's right, but that's no problem because the mode list always starts with the sign ''+" (i.e +mCc ) and this symbol would be index 0 which does not interest me to compare because it is always constant even changing modes.

Conclusion here is finished and fixed script:

Code: Select all

proc pub:addinvite {nick uhost hand chan text} {
     if {$text == ""} { putmsg $chan "Please enter \002nick\002 to add."; return 0 }
	 set t [lindex [split $text] 0]
	 set modos [getchanmode $chan]
	 set modes1 [split "$modos" {}]
	set ti "$t[join !*@*]"
   if {![isinvite $ti $chan]} {
	  newchaninvite $chan $ti invite 0 sticky
	  utimer 5 [list rest_of_commands $modes1 $chan $t] 
proc rest_of_commands {modes1 chan t} { 
	  set modes2 [getchanmode $chan]
	  set largo [string length $modes2]
	  set x 0
	  while  {$x < $largo} {
	  set x [expr {$x + 1}]
	   if {[string index $modes2 $x] in $modes1 == 0} {
          set modchange [string index $modes2 $x]
          pushmode $chan "-[join $modchange]"
          unset modchange
	        }}} 
	 putmsg $chan "$t has been added to the autoinvite database $chan"
	 } else { putmsg $chan "$t is already in the autoinvite database $chan" }
}
Post Reply