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 

call array from variable

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


Joined: 09 Aug 2003
Posts: 19

PostPosted: Sun Apr 16, 2006 9:44 pm    Post subject: call array from variable Reply with quote

imagine u have an array like
Code:

array set test1 {  a 1 
                          b 2 
                          c 3 }

now u can get the values like
Code:

set result $test1(a)


but it doenst work if test1 is saved in a variable like:
Code:

set whatever test1
set result $whatever(a)


why ?
what if i have the array name only in a variable ?

TIA
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Sun Apr 16, 2006 11:29 pm    Post subject: Reply with quote

why would you want to do that?

if you need to pass the array as proc parameter, use [upvar]
_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
StaleJoke
Voice


Joined: 29 Nov 2005
Posts: 10

PostPosted: Thu May 11, 2006 8:51 pm    Post subject: Reply with quote

I have to set an array

Within the proc i want to use the variable like:

$users(1.#Channel1)

$users(2.#Channel1)


$users(1.#AnotherChannel2)

$users(2.#AnotherChannel2)

How should i go about doing it ?
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Fri May 12, 2006 12:31 am    Post subject: Reply with quote

exactly as you did
_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
StaleJoke
Voice


Joined: 29 Nov 2005
Posts: 10

PostPosted: Sat May 13, 2006 9:48 am    Post subject: Reply with quote

array set countem {}

Tcl error [countem]: can't read "users(1.#ChannelA)": no such element in array
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Sat May 13, 2006 1:31 pm    Post subject: Reply with quote

array elements need to be initialized exactly like any other variable, too.
_________________
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...
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