add an eventlistener on an array but outside my table

Hi,

I would add an eventlistener on an array but outside my table. How do you that ?

Thanks in advance.

local group={} group.paper = {} for i = 1, 5 do     group.paper[i] = {};     for k = 1, 2 do         group.paper[i][k] = display.newImageRect(group,papier[i][k],imx,imx)         group.paper[i][k].x = 100         group.paper[i][k].y = 20            group.paper.something[i][k] = "value"       end end group.choose=function(event)     if event.phase == "began" and event.target.isActive then         print( "You touched the object!" )         return true     end end --i must add my eventListener absolutely HERE to interact with others \>\>"group.paper.something" --don't work for i=1,2 do for j=1,5 do group.paper[i][j]:addEventListener("touch", e.choose ) end end

Maybe:

for i=1,2 do     for j=1,5 do         group.paper[i][j]:addEventListener("touch", group.choose )     end end

group instead of e?

just at a glance, you have several problems.
 
First, you’re trying to set values in “group.paper.something[i][k]” which doesn’t exist.

You’d have to declare the tables for those first. e.g.
 
 

group.paper.something = {} group.paper.something[i] = {}

and also, your for loop values are transposed in the bit where you add the listener.

ie, i should be from 1,5 while j should be from 1,2

You might have trouble referencing e.choose, too!

thanks both,

after 7h programming, it’s always stupid typo…i must read again the next day :wink:

Maybe:

for i=1,2 do     for j=1,5 do         group.paper[i][j]:addEventListener("touch", group.choose )     end end

group instead of e?

just at a glance, you have several problems.
 
First, you’re trying to set values in “group.paper.something[i][k]” which doesn’t exist.

You’d have to declare the tables for those first. e.g.
 
 

group.paper.something = {} group.paper.something[i] = {}

and also, your for loop values are transposed in the bit where you add the listener.

ie, i should be from 1,5 while j should be from 1,2

You might have trouble referencing e.choose, too!

thanks both,

after 7h programming, it’s always stupid typo…i must read again the next day :wink: