| View previous topic :: View next topic |
| Author |
Message |
Moonshine Voice
Joined: 09 Aug 2003 Posts: 19
|
Posted: Sun Apr 16, 2006 9:44 pm Post subject: call array from variable |
|
|
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 |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Sun Apr 16, 2006 11:29 pm Post subject: |
|
|
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 |
|
 |
StaleJoke Voice
Joined: 29 Nov 2005 Posts: 10
|
Posted: Thu May 11, 2006 8:51 pm Post subject: |
|
|
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 |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Fri May 12, 2006 12:31 am Post subject: |
|
|
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 |
|
 |
StaleJoke Voice
Joined: 29 Nov 2005 Posts: 10
|
Posted: Sat May 13, 2006 9:48 am Post subject: |
|
|
array set countem {}
Tcl error [countem]: can't read "users(1.#ChannelA)": no such element in array |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Sat May 13, 2006 1:31 pm Post subject: |
|
|
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 |
|
 |
|