You can control it with a boolean flag and if it’s true, it wouldn’t call it again.
Something like this:
local function cutTheRope() rope.isCut = true end .... if (not rope.isCut) then cutTheRope() end
You can control it with a boolean flag and if it’s true, it wouldn’t call it again.
Something like this:
local function cutTheRope() rope.isCut = true end .... if (not rope.isCut) then cutTheRope() end
Hi everyone!
First of all thanks to all that respond to me, I’m trying again to solve the problem with my game and I think i have a clue, I think the problem is when I paint the line to cut the rope, that’s the code:
function drawLine(e) print('drawLine: '..e.phase) if(e.phase == 'began') then initX = e.x initY = e.y elseif(e.phase == 'moved') then line = display.newLine(initX, initY, e.x, e.y) physics.addBody(line, 'static') line.isSensor = true line:addEventListener('collision', ropeCollision) line.strokeWidth = 0 lines:insert(line) elseif(e.phase == 'ended') then display.remove(lines) lines = nil lines = display.newGroup() end end
That function paint a line that when collisions with a rope, It calls to the ropeCollision function that controls if the rope has to be cut or not. But doing a print with the phase, I saw that it does a lot of calls to that event. Am I doing well? Or there is a better way to do this?
You can control it with a boolean flag and if it’s true, it wouldn’t call it again.
Something like this:
local function cutTheRope() rope.isCut = true end .... if (not rope.isCut) then cutTheRope() end