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 

fix sintax commands utimer, after and vwait

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


Joined: 15 Mar 2015
Posts: 317

PostPosted: Fri Apr 10, 2015 6:44 am    Post subject: fix sintax commands utimer, after and vwait Reply with quote

What is the correct syntax for this line?
Code:
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:
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.
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Fri Apr 10, 2015 9:33 am    Post subject: Re: fix sintax commands utimer, after and vwait Reply with quote

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

http://web.archive.org/web/20070205113405/http://www.peterre.info/characters.html

The part you want it about half way down, under:
Quote:

The second golden rule of Tcl for eggdrop



I hope this helps.
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Fri Apr 10, 2015 10:40 am    Post subject: Reply with quote

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
.
Back to top
View user's profile Send private message Visit poster's website
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Fri Apr 10, 2015 12:05 pm    Post subject: Reply with quote

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:
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:
Quote:
utimer 5 [list set modes2 [getchanmode $chan]]

Or the line:
Quote:
after 5000 {set modes2 [getchanmode $chan]}


Error:can't read "modes2": no such variable.

If I add as a line 1 of the proc:
Quote:
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.
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Fri Apr 10, 2015 3:51 pm    Post subject: Reply with quote

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:

...
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.
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Fri Apr 10, 2015 8:55 pm    Post subject: Reply with quote

In your current process, you insist on calling the variable $chan...
Quote:
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...
Quote:
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
.
Back to top
View user's profile Send private message Visit poster's website
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Sat Apr 11, 2015 2:42 am    Post subject: [SOLVED] Reply with quote

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:
Quote:
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:
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" }
}
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