Obj not moving

Hey guys got a small problem with an object that im creating, as the title says it, i cant move it. 

This is my code:

[lua]local obstacle = {}

function Obstacles()
local numObstacles = 30

for i=1,numObstacles,1 do
obstacle = display.newImage(displayGroupBad, “Assets/obstacle.png”, true)
obstacle.x = math.random(100,300)
obstacle.y = math.random(100,620)
obstacle.speed = math.random(4,8)
obstacle.initY = obstacle.y
physics.addBody(obstacle, “static”, {density=0.1, bounce=0.1, friction=.2, radius = 12})
end

end

Obstacles()

function moveObstacles()
if obstacle.x < -50 then
obstacle.x = 500
obstacle.y = math.random(100,320)
obstacle.speed = math.random(2,6)
else
obstacle.x = obstacle.x - obstacle.speed
print(“obstacles should move”)
end
end

moveObstacles()[/lua]

Im not sure what im doing wrong, i did figure out that the moveObstacle function only gets called once, how can i make sure it gets called every update frame?

I noticed a few issues, too much to explain. Also, not into the physics.library stuff so much, so maybe others can help you work through various issues getting things to work the way you want. Best of luck

[lua]

local physics = require( “physics” )
physics.start()

local obstacleArray = {}    – global obstacle array
    
function Obstacles()
local numObstacles = 30
    for i=1,numObstacles,1 do
        obstacleArray[i] = display.newRect(0,0,50,50)
        obstacleArray[i].x = math.random(100,300)
        obstacleArray[i].y = math.random(100,220)
        obstacleArray[i].speed = math.random(4,8)
        obstacleArray[i].initY = obstacleArray[i].y
        physics.addBody(obstacleArray[i], “dynamic”, {density=0.1, bounce=0.1, friction=.2, radius = 12})
    end
    end
    
Obstacles()

function moveObstacles()

    for i=1,#obstacleArray,1 do
        if obstacleArray[i].y > 800 then            
            obstacleArray[i].y = 0
            obstacleArray[i].x = math.random(100,320)
            obstacleArray[i].speed = math.random(2,6)
        else
            obstacleArray[i].x = obstacleArray[i].x - obstacleArray[i].speed
            print(“obstacles should move”)                
        end
    end
end
    
    
local lastTimeChecked = 0   – Global timekeeping
 
local function onEnterFrame(event)
local currentTime = os.time()

        print(" – checking objects.")
        lastTimeChecked = currentTime        
        moveObstacles()
end

    – Now lets keep regularly checking if objects are offscreen
    Runtime:addEventListener(“enterFrame”, onEnterFrame)    
    
    print(" main() done")    
 

[\lua]

Thank you very much! worked perfectly.

Still studying hard to become better at programming, so thanks a lot for the help!

I noticed a few issues, too much to explain. Also, not into the physics.library stuff so much, so maybe others can help you work through various issues getting things to work the way you want. Best of luck

[lua]

local physics = require( “physics” )
physics.start()

local obstacleArray = {}    – global obstacle array
    
function Obstacles()
local numObstacles = 30
    for i=1,numObstacles,1 do
        obstacleArray[i] = display.newRect(0,0,50,50)
        obstacleArray[i].x = math.random(100,300)
        obstacleArray[i].y = math.random(100,220)
        obstacleArray[i].speed = math.random(4,8)
        obstacleArray[i].initY = obstacleArray[i].y
        physics.addBody(obstacleArray[i], “dynamic”, {density=0.1, bounce=0.1, friction=.2, radius = 12})
    end
    end
    
Obstacles()

function moveObstacles()

    for i=1,#obstacleArray,1 do
        if obstacleArray[i].y > 800 then            
            obstacleArray[i].y = 0
            obstacleArray[i].x = math.random(100,320)
            obstacleArray[i].speed = math.random(2,6)
        else
            obstacleArray[i].x = obstacleArray[i].x - obstacleArray[i].speed
            print(“obstacles should move”)                
        end
    end
end
    
    
local lastTimeChecked = 0   – Global timekeeping
 
local function onEnterFrame(event)
local currentTime = os.time()

        print(" – checking objects.")
        lastTimeChecked = currentTime        
        moveObstacles()
end

    – Now lets keep regularly checking if objects are offscreen
    Runtime:addEventListener(“enterFrame”, onEnterFrame)    
    
    print(" main() done")    
 

[\lua]

Thank you very much! worked perfectly.

Still studying hard to become better at programming, so thanks a lot for the help!