Inserting numbers into a table through a for loop

Hello I am trying to condense this code into a for loop like so:  

local theOwnerFlag = _G

            for i = 1,10 do

                if theOwnerFlag[“flag”…i]==true then

                   table.insert(picks,theOwnerFlag[i])

                 end

             end 

–however  it is not registering the insertion of the number into the table.  I think I am doing something wrong in the parenthesis.  Below is what I started with which works but I need to be more flexible.  Also what is a good way to print the corresponding flag.  Thank you.

[lua]

         if (flag1==true) then

            print(‘flag1’)

            table.insert(picks, 1)

          end 

          if (flag2==true) then

            print(‘flag2’)  

            table.insert(picks, 2)

          end 

          if (flag3==true) then

            print(‘flag3’)  

            table.insert(picks, 3)  

          end

          

          if (flag4==true) then

            print(‘flag4’)  

            table.insert(picks, 4)  

          end

          if (flag5==true) then

            print(‘flag5’)  

            table.insert(picks, 5)  

          end

          if (flag6==true) then

            print(‘flag6’)

            table.insert(picks, 6)

          end 

          if (flag7==true) then

            print(‘flag7’)  

            table.insert(picks, 7)

          end 

          if (flag8==true) then

            print(‘flag8’)  

            table.insert(picks, 8)  

          end

          

          if (flag9==true) then

            print(‘flag9’)  

            table.insert(picks, 9)  

          end

          if (flag10==true) then

            print(‘flag10’)  

            table.insert(picks, 10)  

          end

[/lua]

First I wouldn’t assign the global table to your flag table.  How about:

Somewhere define flags as a table:

local flags = {}

and insert the various flags into them (i.e. flags[3] = true; flags[4] = false; – etc)

Then

for i = 1, 10 do

         if (flags[i] == true) then

            print(‘flag’ … i)

            table.insert(picks, i)

          end

end

Thank you, okay I tried this and I still seem to be missing something

[lua]

local flag = {“flag[1]==true”,“flag[2]==true”,“flag[3]==true”,“flag[4]==true”,“flag[5]==true”,“flag[6]==true”,“flags[7]==true”,“flag[8]==true”,“flag[9]==true”,“flag[10]==true”}

for i = 1, 10 do

         if (flag[i] == true) then

            print(‘flag’ … i)

            table.insert(picks, i)

          end

end

also tried like this 

local flag = {“flag[1]”,“flag[2]”,“flag[3]”,“flag[4]”,“flag[5]”,“flag[6]”,“flags[7]”,“flag[8]”,“flag[9]”,“flag[10]”}

[/lua]

flag = {true, true, true, true, true, true, true, true, true, true}

You are using an array indexed by numbers.  You don’t specify strings as the keys.  As such, you just include the values.  The other way to do tables, is what’s known as key-value pairs or hashs.  This is where you would do:

flag = { “somekey” = “someStringvalue”, “someotherkey” = someNumbervalue, “someobjectkey” = someObject }

But since you want to use numbers, you want to use the first version.  You could also do:

flag = {}

flag[1] = true

flag[2] = true

etc.

First I wouldn’t assign the global table to your flag table.  How about:

Somewhere define flags as a table:

local flags = {}

and insert the various flags into them (i.e. flags[3] = true; flags[4] = false; – etc)

Then

for i = 1, 10 do

         if (flags[i] == true) then

            print(‘flag’ … i)

            table.insert(picks, i)

          end

end

Thank you, okay I tried this and I still seem to be missing something

[lua]

local flag = {“flag[1]==true”,“flag[2]==true”,“flag[3]==true”,“flag[4]==true”,“flag[5]==true”,“flag[6]==true”,“flags[7]==true”,“flag[8]==true”,“flag[9]==true”,“flag[10]==true”}

for i = 1, 10 do

         if (flag[i] == true) then

            print(‘flag’ … i)

            table.insert(picks, i)

          end

end

also tried like this 

local flag = {“flag[1]”,“flag[2]”,“flag[3]”,“flag[4]”,“flag[5]”,“flag[6]”,“flags[7]”,“flag[8]”,“flag[9]”,“flag[10]”}

[/lua]

flag = {true, true, true, true, true, true, true, true, true, true}

You are using an array indexed by numbers.  You don’t specify strings as the keys.  As such, you just include the values.  The other way to do tables, is what’s known as key-value pairs or hashs.  This is where you would do:

flag = { “somekey” = “someStringvalue”, “someotherkey” = someNumbervalue, “someobjectkey” = someObject }

But since you want to use numbers, you want to use the first version.  You could also do:

flag = {}

flag[1] = true

flag[2] = true

etc.