Table/For Loop Question

Hi guys,

I’ve got a few questions regarding tables and for loops.
I’m using a table (within a table) where the data is indexed by strings. It already holds some data, and more data can be added to it later on.

a) Is it possible assign a numerical index automatically to the tables, without having to manually?

b) When the For loop is running, it assigns an Event Listener to each object in the table, which I can then manipulate. As mentioned above, I have objects already in the table, and then more can be added later on. My issue with this is that I can only manipulate the objects which have been added later, not the existing ones.
I’ve tried several different ways but can’t seem to get it to work!

Thanks [import]uid: 40538 topic_id: 18220 reply_id: 318220[/import]

I am trying a similar thing and would love to see what you come up with… I will post if I can figure it out. [import]uid: 18783 topic_id: 18220 reply_id: 69712[/import]

what kind of tables are you trying to use?
this:
[lua]local t = {

{x =10,y = {x=20}}

}[/lua]

or this:

[lua]
local t = {

{one = “two”, two = “three”}

}[/lua] [import]uid: 16142 topic_id: 18220 reply_id: 69720[/import]

Can you post up some code.?

A) Would love to see how your currently approaching this, tables automatically get indexed
B) Again would love to see the code, this is easily possible [import]uid: 84637 topic_id: 18220 reply_id: 69784[/import]

Sure!

Table code:

  
local myTable = {}  
  
 myTable.item1 = {  
 image = "item1.png",  
 name = "item1",  
 alpha = 1,  
 x = 200,  
 y = 150  
 }  
  

That is the existing set up with an existing object in it.
Here is the For loop:

local function doSomething(event)  
 if event.phase == "began" then  
 for i=1, #myTable do  
 transition.to(myTable[i], { x = \_W })  
 end  
 end  
 end  
  

And lastly here is the code to add an object to myTable:

  
local function groupIns(event)  
 if event.phase == "began" then  
  
 myName = event.target.name  
 myTable.myName = {  
 image = myName..".png",  
 name = myName,  
 alpha = 1,  
 x = 200,  
 y = 150  
  
 }  
  
  
 table.insert(myTable, myTable.myName)  
 end  
 end  
  

[import]uid: 40538 topic_id: 18220 reply_id: 69790[/import]