How do you end functions after the level is completed?

So when the player loses I want the level to end. And I can remove all my background images, but I don’t know how to end a function that’s controlling some Images before the function has completed.

Thanks in advance!
[import]uid: 70979 topic_id: 11952 reply_id: 311952[/import]

use bool triggers like

gameIsOver = false  
  
function gameLogic()  
 if gameIsOver == false then  
  
 // game logic  
  
 end  
  
 if playerHeadExploded == true then  
  
 gameIsOver = true  
  
 end  
  
end  
  

oh… also remember to remove your event listeners [import]uid: 70635 topic_id: 11952 reply_id: 43607[/import]

Well maybe I didn’t ask my question correctly. I can remove my background Images by using director class, but I can’t remove functions with director class. So my question is, how do you remove a function manually and how do you remove an Image manually?

here’s the function I want to end as soon as I touch a button.
[lua]local function sp ()
for s = 1, 1 do

rand = math.random( 100 )

if (rand < 60) then
p = display.newImage(“platform_1.png”);
p.x = 60 + math.random( 400 )
p.y = 690
physics.addBody( p, “kinematic”,{density = 1, friction = 0.3, bounce = 0.0} )
p.isFixedRotation = true

Velocity ()
bullet ()

else
p = display.newImage(“platform_1.png”);
p.x = 90 + math.random( 320 )
p.y = 690
physics.addBody( p, “kinematic”,{density = 1, friction = 0.3, bounce = 0.0} )
p.isFixedRotation = true

Velocity ()
bullet ()

end
end
end

local spawnPlatforms = timer.performWithDelay( 500, sp, 500 )[/lua]
Oh Ya, Thanks for responding! I really appreciate it! [import]uid: 70979 topic_id: 11952 reply_id: 43670[/import]

timer.cancel ( spawnPlatforms ) ? [import]uid: 70635 topic_id: 11952 reply_id: 46716[/import]