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.

Problem with IF

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

Problem with IF

Post by darton »

Hello!
Look at this script. If the BRenBot is not in that channel, my bot says:"The Servers are down." But it still writes "!gi" in the #admin_chan.
How is it possible that my bot stops writing "!gi" if the BRenBot is not in the #admin_chan?

Code: Select all

bind pub - !gi pub:gi
proc pub:gi {nick uhost hand chan arg} {
global admin_chan public_chan
  if {![onchan BRenBot $admin_chan]} {     
   putquick "privmsg $chan :The Servers are down!"
}
  if {[string equal -nocase $public_chan $chan]} {
   putquick "privmsg $admin_chan :!gi"
 }
}
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

because the next if is independend from first one. you should use ELSEIF like

Code: Select all

  if {![onchan BRenBot $admin_chan]} {     
    puthelp "PRIVMSG $chan :The Servers are down!"
  } elseif {[string equal -nocase $public_chan $chan]} {
    putserv "PRIVMSG $admin_chan :!gi"
  }
to make the 2nd one depend on the previous one.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

No, I already tried this. If the BRenBot was in the #admin_chan, my bot would not write "!gi" in the #admin_chan. So your script does not work.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

darton wrote:If the BRenBot is not in that channel, my bot says:"The Servers are down." But it still writes "!gi" in the #admin_chan.
How is it possible that my bot stops writing "!gi" if the BRenBot is not in the #admin_chan?
darton wrote:No, I already tried this. If the BRenBot was in the #admin_chan, my bot would not write "!gi" in the #admin_chan.
you wrote the opposite in your description. You might want to check spelling (case doesnt matter) of channel and nick. Consider encoding issues of characters above 127. You can also try using 'hand2nick' to also match alternate nicknames, if there is a user entry for the bot.
darton wrote:So your script does not work.
Assuming your script worked as descripted, my changed if construuction should stop your initialy described problem.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

Code: Select all

bind pub - !gi pub:gi
proc pub:gi {nick uhost hand chan arg} {
global admin_chan public_chan
  if {![onchan BRenBot $admin_chan]} {     
   putquick "privmsg $chan :The Servers are down!"
}
  if {[onchan BRenBot $admin_chan]} {
  if {[string equal -nocase $public_chan $chan]} {
   putquick "privmsg $admin_chan :!gi"
  }
 }
}
With this script it works.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

which is equivalent with the code snip I posted, just with some redudant code within the if expressions.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Post Reply