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.

using arrays to make code work when bot is on many channels

Old posts that have not been replied to for several years.
Locked
User avatar
z_one
Master
Posts: 269
Joined: Mon Jan 14, 2002 8:00 pm
Location: Canada

Post by z_one »

I have the following code:

bind join - * betaz
proc betaz {nick uhost hand chan} {
global ipjoinlast

set ipjoinbmask *!*[string tolower [string range $uhost [string first "@" $uhost] end]]

if {$ipjoinlast($chan) != ""} {
set ipjoinlast($chan) "0.0.0.0"
}
...

and when I run it on channel #mychan I get the following error msg, why ?

TCL error [betaz]: can't set "ipjoinlast(#mychan)": variable isn't array
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

bind join - * betaz
proc betaz {nick uhost hand chan} {
global ipjoinlast

set ipjoinbmask($chan) *!*[string tolower [string range $uhost [string first "@" $uhost] end]]
}
Note that you where using 2 set commands on the same var name, but of 2 different types, which is the reason for the error.
User avatar
z_one
Master
Posts: 269
Joined: Mon Jan 14, 2002 8:00 pm
Location: Canada

Post by z_one »

I'm sorry I typed the following line wrong:

set ipjoinbmask *!*[string tolower [string range $uhost [string first "@" $uhost] end]]

actually I used this in my code (using and array to make the variable channel specific too)

set ipjoinbmask($chan) *!*[string tolower [string range $uhost [string first "@" $uhost] end]]

-----

Which variable am I setting twice ?
I have:

set ipjoinbmask($chan)

set ipjoinlast($chan)

They are two different variables.
I'm sorry I didn't get ur last point, if there's anything I missed pls feel free to explain :smile:

Thanks in advance
User avatar
z_one
Master
Posts: 269
Joined: Mon Jan 14, 2002 8:00 pm
Location: Canada

Post by z_one »

Perhaps I should rephrase to help u guys see what I mean :smile:
I read an article that specifies that the global command converts entire arrays, not just individual strings:
http://www.suninet.nl/tclguide/tclguide-ch5.html#ch5.5

-----

Why then when I initialize as follows:

proc betaz {nick uhost hand chan} {
global ipjoinlast
if (![info exists ipjoinlast($chan)]) {
set ipjoinlast($chan) ""
}
...
}

I get the following error:

TCL error [betaz]: can't set "ipjoinlast(#mychannel)": variable isn't array

<font size=-1>[ This Message was edited by: z_one on 2002-01-15 09:06 ]</font>
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

You must have already set the variable somewhere else (perhaps initialization). Once you set a variable, it can no longer be an array. Just get rid of that part and it should work.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

[oops double post]

<font size=-1>[ This Message was edited by: stdragon on 2002-01-15 12:25 ]</font>
Locked