Hi,
Here is my problem.
I have created a table call boxes and a group call elements
[lua]local boxes = {}
local elements = display.newGroup ()[/lua]
and I also have a function to add boxes
[lua]local function addboxes ()
local height = math.random ( display.contentCenterY - 160, display.contentCenterY + 160)
box = display.newImageRect ( “box.png”, 110, 350)
box.x = w + 100
box.y = height
elements:insert (box)
boxes[#boxes+1] = box
end
timer.performWithDelay ( 5000, addboxes, -1)
[/lua]
After that, I want to move all the boxes from the right side to left side of the simulator.
[lua]function moveboxes ()
for a = elements.numChildren, 1, -1 do
if (elements[a].x < display.contentCenterX - 120) then
end
if ( elements[a].x > -100 ) then
elements[a].x = elements[a].x - 12
else
elements:remove (elements[a])
elements[a] = nil
end
end
end
timer.performWithDelay ( 50, moveboxes, -1)
[/lua]
Also, when the box move to x point, I want it to print (“hi”)
However, after the function printed hi for the first column, and the second column went error…
here is my code
[lua]local function boxMoveDown ()
local firstBox = boxes[1] --Here might be the problem, I’m not so sure
if (firstBox.x < 100) then
print ( “hi” )
end
end
[/lua]