re-calling a local function

function addBlock(range,dur)

  local x =  display.contentHeight/12

  local y = math.random((display.contentHeight+(display.contentHeight*0.2)) * 0.7)

  local y2 = display.contentHeight -y

  local rect1 = display.newRect(range+(0.5*x),0.5*y-(0.1*display.contentHeight),x,y)

  local rect2 = display.newRect(range+(0.5*x),(1/2*y2)+y+(0.09*display.contentHeight),x,y2)

  scene.view:insert(rect1)

  scene.view:insert(rect2)

  local function renew(obj)

    print(“renew”)

    obj.x =  display.contentWidth + (0.5*obj.contentWidth)

    obj.trans = transition.to(obj, {x = (-1/2*obj.x),y = obj.y,time = 4000,onConplete=renew})

  end

  rect1.trans = transition.to(rect1, {x = (-1/2*x),y = rect1.y,time = dur,onConplete=renew})

  rect2.trans = transition.to(rect2, {x = (-1/2*x),y = rect2.y,time = dur,onComplete=renew})

end

I’m trying to make the block respawn from the right of the screen (with a new random position). However, it only trigger the rect1’s onComplete, rect2’s cannot be triggered. and I try to repeat the function renew too (but it doesn’t work). Could anyone please help me how the repeat the function and why rect2’s onComplete never trigger?

Hi @toankst

Your code should works fine. Only typo.

You typed onConplete instead of onComplete (2 locations)

burhan

only this could convey my reaction…

http://www.youtube.com/watch?v=6nSKkwzwdW4

Thank you very much! I have not get used to corona’s interface, it does detect syntax error but not grammar, which I was a little careless to ignore…

Hi @toankst

Your code should works fine. Only typo.

You typed onConplete instead of onComplete (2 locations)

burhan

only this could convey my reaction…

http://www.youtube.com/watch?v=6nSKkwzwdW4

Thank you very much! I have not get used to corona’s interface, it does detect syntax error but not grammar, which I was a little careless to ignore…