A newbie question again. "Tracking the object.x and object.y"

FIRST CASE : If i create an object outside of a function and applyForce to it i can track the object.x and object.y

local ball = display.newImage( "ball.png")   
ball.x = 10  
ball.y = 10   
ball:setReferencePoint(display.CenterReferencePoint);  
physics.addBody( ball, { density=0.02, friction=0.1, bounce=0.5,radius=20 } )  
ball:applyLinearImpulse ( 0.1, -0.2, ball.x, ball.y)  
  
function start()  
print(ball.x)  
print(ball.y)  
end  
  
Runtime:addEventListener("enterFrame", start)  

SECOND CASE: If I create an object instances inside of a function calling it with a timer how can i track the object.x and object.y??

function createball()  
ball = display.newImage( "ball.png")   
ball.x = 10  
ball.y = 10   
ball:setReferencePoint(display.CenterReferencePoint);  
physics.addBody( ball, { density=0.02, friction=0.1, bounce=0.5,radius=20 } )  
ball:applyLinearImpulse ( 0.1, -0.2, ball.x, ball.y)  
  
function start()  
print(ball.x)  
print(ball.y)  
end  
  
timer.performWithDelay (1000,createball,100)   
Runtime:addEventListener("enterFrame", start)  

Any help? [import]uid: 74718 topic_id: 12703 reply_id: 312703[/import]

Am not sure what you are trying to achieve from this code…
why is createball called 100 times ? are you trying to create 100 balls ?

the error you are getting is due to positioning of the statements.
it seems like the start function is called before the ball is created inside createball function. [import]uid: 71210 topic_id: 12703 reply_id: 46523[/import]

Yes I want to create 100 ball. Ok you are right thank you so much, but I changed to code like below and ;

function createball()  
ball = display.newImage( "ball.png")   
ball.x = 10  
ball.y = 10   
ball:setReferencePoint(display.CenterReferencePoint);  
physics.addBody( ball, { density=0.02, friction=0.1, bounce=0.5,radius=20 } )  
ball:applyLinearImpulse ( 0.1, -0.2, ball.x, ball.y)  
   
function start()  
print(ball.x)  
print(ball.y)  
end  
  
function trig()  
Runtime:addEventListener("enterFrame", start)  
end  
  
timer.performWithDelay (1000,createball,100)   
timer.performWithDelay (2000,trig)   

and ball.x and ball.y gives nil. at the end I end up with

i = 0  
balltable = {}  
function createball()  
 i = i + 1   
 ball = display.newImage( "ball.png")   
 ball.x = 10  
 ball.y = 10   
 ball:setReferencePoint(display.CenterReferencePoint);  
 physics.addBody( ball, { density=0.02, friction=0.1, bounce=0.5,radius=20 } )  
 ball:applyLinearImpulse ( 0.1, -0.2, ball.x, ball.y)  
 balltable[i]=ball  
  
function start()  
 print(balltable[i].x) -- I can track with i or table number  
 print(balltable[i].y)  
end  
  
function trig()  
 Runtime:addEventListener("enterFrame", start)  
end  
  
timer.performWithDelay (1000,createball,100)   
timer.performWithDelay (2000,trig)   

But I am not sure if this type of usage is ok, anyway thank you [import]uid: 74718 topic_id: 12703 reply_id: 46575[/import]

Yeap… if you want to create 100 balls this will be a better option. [import]uid: 71210 topic_id: 12703 reply_id: 46579[/import]