How to stop a function

Hi, I would like to know how is it possibile to stop a function, thanks.

[import]uid: 76800 topic_id: 25744 reply_id: 325744[/import]

More details please - how is the function being called?

Showing some code would be useful here :slight_smile: [import]uid: 52491 topic_id: 25744 reply_id: 104178[/import]

sure, here’s my code:

local function nuvola()  
  
local starTable = {}   
   
function initStar()  
 local star1 = {}  
 star1.imgpath = "nuvola.png";   
 star1.movementSpeed = 10000;   
 table.insert(starTable, star1);  
  
  
end   
   
function getRandomStar()  
 local temp = starTable[math.random(1, #starTable)]   
 local randomStar = display.newImage(temp.imgpath)   
 randomStar.myName = "star"   
 randomStar.movementSpeed = temp.movementSpeed;   
 randomStar.x = math.random(0,\_W)   
 randomStar.y = -50  
  
 starMove = transition.to(randomStar, {  
 time=randomStar.movementSpeed,   
 y=\_H,  
 onComplete = function(self) self.parent:remove(self); self = nil; end  
 })   
end  
   
function startGame()  
 starTimer1 = timer.performWithDelay(1700,getRandomStar, 0)  
 starTimer2 = timer.performWithDelay(2300,getRandomStar, 0)  
 starTimer3 = timer.performWithDelay(2700,getRandomStar, 0)   
end  
   
 initStar()  
startGame()  
  
end  
  
tmr = timer.performWithDelay (15000, nuvola, -1)   

as you can see, this function begins 15 seconds after the game started, I would like to stop this function 20 seconds after the function started.
[import]uid: 76800 topic_id: 25744 reply_id: 104203[/import]

You’d write a function that cancels all times and existing transitions - and you might possibly want to put your timers in a table to make that easier as with this code you remake your starTimers multiple times. (Once every 15 seconds.)

You can use timer.cancel and transition.cancel in said function.

Peach :slight_smile: [import]uid: 52491 topic_id: 25744 reply_id: 104369[/import]