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.

array of array

Old posts that have not been replied to for several years.
Locked
User avatar
CrazyCat
Revered One
Posts: 1279
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

array of array

Post by CrazyCat »

well, another trouble...
I want to create an array of array, to get this kind of values:
test_array(first_channel)(0) = users
test_array(first_channel)(1) = voices
test_array(first_channel)(2) = halfs
test_array(first_channel)(3) = opers
test_array(second_channel)(0) = users
test_array(second_channel)(1) = voices
test_array(second_channel)(2) = halfs
test_array(second_channel)(3) = opers
but first_channel, second_channel are variables coming from [channels]

So, I make:

Code: Select all

foreach my_chan [channels] {
set test_array([string tolower $my_chan]) { "0" "0" "0" "0"}
}
....
proc fillin {channel} {
global test_array
set test_array((${channel})(0) "x"
set test_array((${channel})(1) "y"
....
putlog "$test_array((${channel})(0) -- $test_array((${channel})(1)"
}
And the response is always: Tcl error [fillin]: can't read "test_array((yourchan)": no such element in array (my channel is #yourchan)
User avatar
caesar
Mint Rubber
Posts: 3777
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

instead of test_array(second_channel)(0) = users and so on use something like test_array(second_channel:0) = users ..
Once the game is over, the king and the pawn go back in the same box.
User avatar
CrazyCat
Revered One
Posts: 1279
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

YESSSSSSSSS!!!
thanx a lot :)
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

or a more common practice is to use commas to represent (not really multi-dimensional for all intensive purposes) multi-dimensional arrays...(Also more practical in this case in particular, as channel names may contain a :, but are not allowed to contain a ,)...

ie. $test_array(#chan1,0) , $test_array(#chan2,1) ...
User avatar
CrazyCat
Revered One
Posts: 1279
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

I'll keep it in my mind and won't re-ask for it :)
Thanx a lot
Locked