[RESOLVED] timer.performWithDelay problem when triggering collision events

Hi everyone, I’ve been on this for hours and feel a bit stupid… Considering the complexity of my current code, basic syntax seems to be causing me a problem.

I’m trying to create a pivot joint between two colliding physics objects (at the point of collision). I’m well aware of the limitations of running a script whilst a collision event is ‘calculating’, so I’ve followed the advise; ‘add a timer before triggering the event’. I just can’t get it to work, I’m tearing my hair out. I know I’m missing something obvious, but I’ve been looking at the code for that long my brain is starting to fry.

Example:
[lua]local jointSensor = display.newCircle( 200, 420, 20 )
physics.addBody( jointSensor, {isSensor=true, radius = 60 } )
jointSensor.isVisible = true

local connect = function (event, self)
if event.other.name == “ball” and event.phase == “began” then
physics.newJoint( “pivot”, jointSensor, mainball, 30, 36 )
end
timer.performWithDelay(10, connect, 1)
end

jointSensor:addEventListener(“collision”, connect)[/lua]

‘ball’ is a dynamic physics object… Obviously I’ve implemented the timer function in the wrong way. Terminal reports: “attempt to call field ‘performWithDelay’ (a nil value)”.

Really bashing my head against the wall, any help will be gratefully received.

Mark
[import]uid: 176868 topic_id: 35467 reply_id: 335467[/import]

Tried this version too, but same error from terminal:

[lua]local connect = function (event, self)
if event.other.name == “mainball” and event.phase == “began” then
physics.newJoint( “pivot”, jointSensor, mainball, 30,36 )
timer.performWithDelay(1, function()
end)
end
end [/lua]

Stuck! [import]uid: 176868 topic_id: 35467 reply_id: 140922[/import]

I can’t help with the physics side of it; no ideas, really, but…

a. A delay of 1 is almost irrelevant, I doubt there is a time delay between 1 and 20ms due to the execution time

b. If you’re getting .performWithDelay() is nil, that could mean you might have accidentally overwrote the timer library somewhere with an object called timer? might want to print(timer) beforehand to check. [import]uid: 41884 topic_id: 35467 reply_id: 140932[/import]

You must be psychic… I was just about to throw myself of the bridge when I remembered that I’m using a countdown clock (a kind of shot timer), sure enough, I’d called it ‘Timer’, doh! Renamed it to clock and we’re all good.

Resolved. Yay! [import]uid: 176868 topic_id: 35467 reply_id: 140936[/import]

Tried this version too, but same error from terminal:

[lua]local connect = function (event, self)
if event.other.name == “mainball” and event.phase == “began” then
physics.newJoint( “pivot”, jointSensor, mainball, 30,36 )
timer.performWithDelay(1, function()
end)
end
end [/lua]

Stuck! [import]uid: 176868 topic_id: 35467 reply_id: 140922[/import]

I can’t help with the physics side of it; no ideas, really, but…

a. A delay of 1 is almost irrelevant, I doubt there is a time delay between 1 and 20ms due to the execution time

b. If you’re getting .performWithDelay() is nil, that could mean you might have accidentally overwrote the timer library somewhere with an object called timer? might want to print(timer) beforehand to check. [import]uid: 41884 topic_id: 35467 reply_id: 140932[/import]

You must be psychic… I was just about to throw myself of the bridge when I remembered that I’m using a countdown clock (a kind of shot timer), sure enough, I’d called it ‘Timer’, doh! Renamed it to clock and we’re all good.

Resolved. Yay! [import]uid: 176868 topic_id: 35467 reply_id: 140936[/import]