for loop on accelerometer event

Hi, I’m crating a side scroller in which the movement is driven by the accelerometer event. Initially, I wanted to group all graphical objects and move them at once, but I’m using the physics and grouping creates undesirable results. Therefore, I have to keep the physical objects separately. In order to simplify my code I list all of the object in a array and then try to iterate through them on accelerometer event in order to move them (my way of grouping things), however for some reason it’s not working. Here’s the code (any ideas why it is not working? I’m not getting any errors):

– table of objects
local enemyTable = {}
– generating objects
for i=1, 5 do
local enemy = display.newCircle(0, 0, 20)
enemy.x = 150 * i
enemy.y = groundPos-10 – position of the ground -10 pixels
enemy:setFillColor( 0, 0, 255 ) – blue
enemy.myName = “Enemy”
– add physics
physics.addBody( enemy, “static”, { density = 1.0, friction = 0.1, bounce = 0.0, radius = 20 } )
enemy.isFixedRotation = true
table.insert(enemyTable, enemy)
end

– direction of movement
local moveDir = 0

– this will do the loop
local function onAccelerate( event )
moveDir = event.yGravity

– move objects in the array

if moveDir<0 then

for i=1, #enemyTable do
enemyTable[i].x = enemyTable[i].x - (moveDir * 20)
end
end

end

Runtime:addEventListener (“accelerometer”, onAccelerate);

If you have any ideas why this doesn’t work please write your suggestions.

Many thanks in advance!
PJ [import]uid: 74021 topic_id: 12594 reply_id: 312594[/import]

I fixed this problem. There was a mistake in another place in my code. [import]uid: 74021 topic_id: 12594 reply_id: 47715[/import]