how to call function in timer.performWithDelay()

Hello there,

please if someone can help me.  how I can call a function in timer.performWithdelay().  I have bellow example.

function displayImg( imgIndex, x, y )

     

     local dsp = display.newGroup()

     local img2Display = display.newImageRect(img[imgIndex], 100, 100)

     img2.anchorX = 0

     img2.anchorY = 0

     img2.x = x

     img2.y = y

    dsp:insert( img2Display )

end

example:

tmr = timer.performWithDelay(1000, displayImg( 5, 100, 100) )

it did not work…

can somebody help?

thanks

you cant pass parameters directly through a timer.performwithdelay. instead you can use lua closures e.g

tmr = timer.performWithDelay(1000, function () displayImg( 5, 100, 100) return true end,1 )

I try this one and its working… thanks for your experties 86lemonade68. I really appreciated I am new here and I really appreciated the people like you willing to share some knowledge…

thanks again…

you cant pass parameters directly through a timer.performwithdelay. instead you can use lua closures e.g

tmr = timer.performWithDelay(1000, function () displayImg( 5, 100, 100) return true end,1 )

I try this one and its working… thanks for your experties 86lemonade68. I really appreciated I am new here and I really appreciated the people like you willing to share some knowledge…

thanks again…