I want to make 50 text display objects and later add touch event to them.
I try to use for… do statement to do so, but I can’t get it to work me 
here is the code:
local i = 0
for i = 50,1,-1 do
local myText(1) = display.newText(“TouchMe”, 0, 0, native.systemFont, 16)
myText(i).y = 15 * i
end
I can’t figure out why… please help…
Thanks
[import]uid: 63983 topic_id: 11358 reply_id: 311358[/import]
I think you want something more like this:
[lua]local i
local myText = {}
for i = 50,1,-1 do
myText[i] = display.newText(“TouchMe”, 0, 0, native.systemFont, 16)
myText[i].y = 15 * i
end[/lua]
- Initialize your myText table before using it
- Don’t refer to it as local within the loop; you want to reference the myText you initialized earlier.
- When using an index on a table, use brackets [] instead of parentheses ().
Hope that makes sense (and is what you were looking for…hehe)
Sincerely,
Christopher David YUDICHAK [import]uid: 21712 topic_id: 11358 reply_id: 41204[/import]
Thanks, It works the way I wanted. [import]uid: 63983 topic_id: 11358 reply_id: 41220[/import]