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 

Problem with arrays

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


Joined: 23 Jul 2006
Posts: 40

PostPosted: Sat Nov 25, 2006 9:09 pm    Post subject: Problem with arrays Reply with quote

Alright, here's what I got:

Code:
bind notc - * battle:noticekick
bind pubm - * battle:mainchan
bind time - "00 * * * *" battle:unsetwarn

array set warned {}


proc battle:noticekick {nick uhost handle text dest} {
   if {[validchan $dest]} {
      set dest [string tolower $dest]
      if {[string equal $dest "#century0"] && ![matchattr $handle D]} {
         putquick "PRIVMSG Chanserv :#century0 addtimedban $nick 3m Please for the love all that’s holy and rocky don’t do that. Trust us if we want the channel to make a large beeping sound…..we can do it ourselves. \[3 minute ban\]"
      }
   }
}

proc battle:warnnick {nick host hand chan text} {
   putserv "NOTICE $nick :You almost stepped on a landmine there Mr. Rockstar. Check out @rockrules and @advertising"
}


proc battle:mainchan {nick host hand chan text} {
   global warned
   set chan [string tolower $chan]
   if {[string equal $chan "#century0"]} {
      set text [stripcodes bcr $text]
         if {[string match -nocase "*hotrockplanet*" $text] || [string match -nocase "*egln*" $text]} {
            return 0
         } elseif {[string match -nocase "*#*" $text] || [string match -nocase "*www*" $text] || [string match -nocase "*.com*" $text] || [string match -nocase "*.net*" $text] || [string match -nocase "*.org*" $text] || [string match -nocase "*http*" $text]} {
            if {$warned($nick) == 1} {
               putserv "PRIVMSG Chanserv :#century0 addtimedban $nick 3m Advertising is not permitted in #hotrockplanet. Please read @advertising and @rockrules when you return. \[3 minute ban\]"
               set warned($nick) 0
            } else {
               set warned($nick) 1
               battle:warnnick nick host hand chan text
               }
         } else {
            return 0
         }
   }
}

proc battle:unsetwarn { min hour day month year } {
   global warned
    foreach nick [array names warned] {
       if {$warned($nick) == 1} {
         set $warned($nick) 0
        }
   }
}


Here's the error:
Code:
[19:59] Tcl error [battle:mainchan]: can't read "warned(HRock|Darin)": no such element in array


~Nara
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sat Nov 25, 2006 9:14 pm    Post subject: Reply with quote

Help us to help you
Back to top
View user's profile Send private message
Nara
Halfop


Joined: 23 Jul 2006
Posts: 40

PostPosted: Sat Nov 25, 2006 11:19 pm    Post subject: Reply with quote

Besides the fact it's probably an obvious method, I did follow that topic unless you're talking about .set errorInfo?

If so:

Code:
[22:18] #Century0# set errorInfo
Currently: can't read "warned(Ging_sleepTIME)": no such element in array
Currently:     while executing
Currently: "if {$warned($nick) == 1} {
Currently:                                      putserv "PRIVMSG Chanserv :#cent                                              ury0 addtimedban $nick 3m Advertising is not permitted in #hotrockplanet. Please                                               read ..."
Currently:     (procedure "battle:mainchan" line 9)
Currently:     invoked from within
Currently: "battle:mainchan $_pubm1 $_pubm2 $_pubm3 $_pubm4 $_pubm5"
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sat Nov 25, 2006 11:31 pm    Post subject: Reply with quote

Code:

if {$warned($nick) == 1} {
               putserv "PRIVMSG Chanserv :#century0 addtimedban $nick 3m Advertising is not permitted in #hotrockplanet. Please read @advertising and @rockrules when you return. \[3 minute ban\]"
               set warned($nick) 0

You test the var before ever setting it elsewhere (line 9 of the proc)..
Back to top
View user's profile Send private message
Nara
Halfop


Joined: 23 Jul 2006
Posts: 40

PostPosted: Sat Nov 25, 2006 11:38 pm    Post subject: Reply with quote

Well, can you help me come up with a way to initialize the variable, because I can't just set it to a value because it could be 1 or 0.
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sat Nov 25, 2006 11:45 pm    Post subject: Reply with quote

You have to at least init the var with the nick, so somewhere you need to do like: set warned($nick) ""
Back to top
View user's profile Send private message
Nara
Halfop


Joined: 23 Jul 2006
Posts: 40

PostPosted: Sat Nov 25, 2006 11:52 pm    Post subject: Reply with quote

What's the command to see names in a chan, preferably one I could use like [foreach nick chan]?
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sun Nov 26, 2006 12:23 am    Post subject: Reply with quote

http://www.eggheads.org/support/egghtml/1.6.15/tcl-commands.html
Back to top
View user's profile Send private message
DragnLord
Owner


Joined: 24 Jan 2004
Posts: 711
Location: C'ville, Virginia, USA

PostPosted: Sun Nov 26, 2006 12:27 am    Post subject: Reply with quote

look here for "chanlist"
Back to top
View user's profile Send private message
Nara
Halfop


Joined: 23 Jul 2006
Posts: 40

PostPosted: Sun Nov 26, 2006 8:44 pm    Post subject: Reply with quote

Alright, this is my solution, but sadly, it doesn't work for the main part (if $nick == $botnick, then find all nicks in chan and set them to 0.

Code:
bind join - "#century0 *" battle:setnicks

array set warned {}

proc battle:setnicks {nick uhost handle chan} {
   global warned botnick
   if {$nick == $botnick} {
      foreach nick [chanlist #century0] {
         set warned($nick) 0
         }
   } else {
      set warned($nick) 0
   }
}


Could it be because the code is executing before the bot has got the list or did I just do it wrong?
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sun Nov 26, 2006 10:05 pm    Post subject: Reply with quote

You're testing {$nick == $botnick} first, so of course the part where the array is being set, is not going to be set unless the nick is the botnick..

You probably want to do {foreach nick [chanlist #century0]} {if {$nick != $botnick} and so on, so that the arrays are set for each nick except botnick...But, actually, that will only work on existing names in the channel, and not when they join/part/quit. It would be more reasonable to test for some condition that you're trying to warn for, set the array var for the nick, then execute whatever warning/punishment..

The logic and intention of your original script is not very clear, so it's difficult to make suggestions..
Back to top
View user's profile Send private message
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Mon Nov 27, 2006 1:11 am    Post subject: Reply with quote

Instead of a foreach loop to catch all the users on the channel and setting them in an array, why not check if the variable for the user exists then set it if not.

For example:

Code:
proc battle:mainchan {nick host hand chan text} {
   global warned
   set chan [string tolower $chan]
   if {[string equal $chan "#century0"]} {
     if {![info exists warned($nick)]} {
       set warned($nick) "0"
       return
     }
     ..... rest of code here ......
}


Also maybe put all of those string match's into one simple regexp.

Hope this helps..!
_________________
r0t3n @ #r0t3n @ Quakenet
Back to top
View user's profile Send private message MSN Messenger
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