[Resolved] How to stop a timer

Hi, I’m new to corona and in my game I have the following function:

 local function stelle()  
  
local starTable = {}  
   
function initStar()  
 local star1 = {}  
 star1.imgpath = "star1.png";  
 star1.movementSpeed = 10000;   
 table.insert(starTable, star1);   
  
 local star2 = {}  
 star2.imgpath = "star2.png";  
 star2.movementSpeed = 12000;  
 table.insert(starTable, star2);   
  
  
 local star3 = {}  
 star3.imgpath = "star3.png";  
 star3.movementSpeed = 14000;  
 table.insert(starTable, star3);  
end --END initStar()   
   
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   
 randomStar.rotation = math.random(0,360)   
 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 (75000, stelle, 0)  

As you can see, this function starts 75 seconds after my game is started, now I would like to stop this function (I have to stop “tmr” I suppose) for example 15 seconds later. How can I do that?

Thanks a lot!! :slight_smile: [import]uid: 111398 topic_id: 32293 reply_id: 332293[/import]

I have this “general” function in my main.lua . All timers go into my tms timer stash.

tms = {}  
  
function cancelAllTimers()  
 local k, v  
 for k,v in pairs(tms) do  
 timer.cancel( v )  
 v = nil; k = nil  
 end  
 tms = nil  
 tms = {}  
end  

in the other .lua files I add all times into the stash, so I can cancel them in one go :

tms[#tms+1] = timer.performWithDelay( 100, ProductBlink , 10 ) [import]uid: 75958 topic_id: 32293 reply_id: 128466[/import]

Thanks for your help :slight_smile:

I found a solution using the following code:

[code]

local function canceltimer()
timer.cancel(tmr)
tmr = nil;
end

deletetmr = timer.performWithDelay (90000, canceltimer, 0)

[/code] [import]uid: 111398 topic_id: 32293 reply_id: 128483[/import]

I have this “general” function in my main.lua . All timers go into my tms timer stash.

tms = {}  
  
function cancelAllTimers()  
 local k, v  
 for k,v in pairs(tms) do  
 timer.cancel( v )  
 v = nil; k = nil  
 end  
 tms = nil  
 tms = {}  
end  

in the other .lua files I add all times into the stash, so I can cancel them in one go :

tms[#tms+1] = timer.performWithDelay( 100, ProductBlink , 10 ) [import]uid: 75958 topic_id: 32293 reply_id: 128466[/import]

Thanks for your help :slight_smile:

I found a solution using the following code:

[code]

local function canceltimer()
timer.cancel(tmr)
tmr = nil;
end

deletetmr = timer.performWithDelay (90000, canceltimer, 0)

[/code] [import]uid: 111398 topic_id: 32293 reply_id: 128483[/import]