View Full Version : Using a for loop to create multiple tables
TJ_Tigger
04-19-2004, 10:41 PM
I am trying to create a for loop to create multiple tables with an incremental index name. I am not thinking straight tonight so the solution eludes me.
for x = 1,10 do
mytable..x = {}
end
That is one of the things I tried but AMS gave me a hard time about the syntax.
Syntax Error: [Location="Intro:Button3", Event "On Click", Line=2]
Error Detail: [`=' expected near `..'] in [mytable .. x = {}]
Any suggestions?
Stefan_M
04-20-2004, 12:05 AM
did you try
for x = 1,10 do
mytable[x] = {}
end
Stefan
TJ_Tigger
04-20-2004, 07:59 AM
Thanks Stefan,
I was tired and a little under the weather and could not articulate my question very well. I am able to create one table in the fashion you provided, but what I was trying to do was create dynamically 10 different tables like such
mytable1
mytable2
mytable3
mytable4
mytable5
mytable6
mytable7
mytable8
mytable9
mytable10
I am parsing out a text file that has multiple entries and I was hoping to create multiple tables from one file that were numbered incrementally. Will continue to plug away when I have time today.
Tigg
Just a thought, but you could create one table with each row of the table being another table.
Thanks Stefan,
I was tired and a little under the weather and could not articulate my question very well. I am able to create one table in the fashion you provided, but what I was trying to do was create dynamically 10 different tables like such
mytable1
mytable2
mytable3
mytable4
mytable5
mytable6
mytable7
mytable8
mytable9
mytable10
I am parsing out a text file that has multiple entries and I was hoping to create multiple tables from one file that were numbered incrementally. Will continue to plug away when I have time today.
Tigg
Stefan_M
04-20-2004, 08:30 AM
Extreme programming:
generat a table.lua file
for x = 1,10 do
text="mytable"..x.." = {}"
TextFile.WriteFromString(...text...)
end
load the table.lua file with
dofile(table.lua)
:D
Stefan
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.