Using a for loop to create multiple tables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • TJ_Tigger
    Indigo Rose Customer
    • Sep 2002
    • 3159

    Using a for loop to create multiple tables

    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?
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
  • Stefan_M
    Indigo Rose Customer
    • Nov 2003
    • 315

    #2
    did you try

    for x = 1,10 do
    mytable[x] = {}
    end


    Stefan
    "With a rubber duck, one's never alone."

    Douglas Adams, The Hitchhiker's Guide to the Galaxy

    Comment

    • TJ_Tigger
      Indigo Rose Customer
      • Sep 2002
      • 3159

      #3
      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
      TJ-Tigger
      "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
      "Draco dormiens nunquam titillandus."
      Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

      Comment

      • Worm
        Indigo Rose Customer
        • Jul 2002
        • 3971

        #4
        Just a thought, but you could create one table with each row of the table being another table.

        Originally posted by TJ_Tigger
        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

        Comment

        • Stefan_M
          Indigo Rose Customer
          • Nov 2003
          • 315

          #5
          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)


          Stefan
          "With a rubber duck, one's never alone."

          Douglas Adams, The Hitchhiker's Guide to the Galaxy

          Comment

          Working...
          X