how to cancel a normal function from running ?!

hi,
here’s a sample for the function:

local function fly()
local steady = function()
instance1:pause()
timer.performWithDelay(500, fly, 1)
end
instance1:play()
timer.performWithDelay(3000, steady, 1)
end
fly()

this function is working in a game scene; when i turn back to the menu scene, this function is still working and doing error at the play() and pause() methods … as the instance1 sprite isn’t there
So i want to stop this function before i go out from the game scene

is there any property like removeSelf() for the objects … or something like that for the functions !? [import]uid: 96659 topic_id: 18640 reply_id: 318640[/import]

http://www.lua.org/pil/4.4.html
i suggest to read some manuals [import]uid: 16142 topic_id: 18640 reply_id: 71609[/import]

If you are removing “instance1” when you go back to the menu, then I think you can just do a check to see if “instance1” exists.

local function fly()  
 local steady = function()  
 if instance1 then  
 instance1:pause()  
 timer.performWithDelay(500, fly, 1)  
 end  
 end  
  
 if instance1 then   
 instance1:play()  
 timer.performWithDelay(3000, steady, 1)  
 end  
end  
fly()  

[import]uid: 94868 topic_id: 18640 reply_id: 71613[/import]

@ darkconsoles
the ‘return’ didn’t work, i put it in both of them and it’s not workin’ :s:s
… i tried to use a flag variable … and nothin happen [import]uid: 96659 topic_id: 18640 reply_id: 71616[/import]

hi Screaming Leaf,
… i did your condition … and it’s still working … i’m loading back the menu scene … and in the debugger, an error in the game scene is shown up !!

i’m turning to green
should i use another method instead of director:changeScene
[import]uid: 96659 topic_id: 18640 reply_id: 71624[/import]

you can always set
[lua] fly = nil [/lua]
Also it is always wise to cancel your timers and transitions before changing scenes. [import]uid: 64174 topic_id: 18640 reply_id: 71627[/import]

thnx Satheesh … maybe it’s the only thing i forgot to do…although i’m using another timers and i cancel them :S
… anyway thanks [import]uid: 96659 topic_id: 18640 reply_id: 71633[/import]