Declaring alot of variables, with arrays or loops.

Old posts that have not been replied to for several years.
Locked
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Declaring alot of variables, with arrays or loops.

Post by awyeah »

Hi,

I have a script using alot of variables.
And declaring them is a real problem, I guess. :x

The variables say are, char1, char2, char3...... char115. (char1 - char115)
I can do that manually but, that is really hectic. :-?

What here is I came up with a peiece of code
to do it. But it doesn't work. :cry:

Code: Select all

for {set i 1} {$i < 116} {incr i} {
 set char($i) 0
}

#Even tried, set char[$i], or set char$i, but they don't work!
Also in C I remember, you could declare them
such as using arrays, set char[115]? would this
declare 115 variables from, index 0 to index 115?

If anyone, can help me with this, I would be very thankful! :mrgreen:
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

There is nothing wrong with your code. It should work without problem.
from tclsh:
% for {set i 1} {$i < 116} {incr i} { set char($i) 0 }
% set char(41)
0
% set char(115)
0
...or you could use the while loop instead

Code: Select all

set i 1
while {$i<116} { set char($i) 0 ; incr i }
char[115] does not work in tcl :)
Elen sila lúmenn' omentielvo
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Umm... thanks Papillon.. yeah it works ;)
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Locked