I have the following code which fades in and out an object using transitions. After a certain amount of time I’d like to cancel these transitions and remove them from memory.
However after calling the clearTransitions() method below I can see that the tables are cleared (size is 0) however the transitions still run. Why do they still run? Any info would be greatly appreciated.
arrowFadeInTransitions = {} arrowFadeOutTransitions = {} arrows = {rect1, rect2, rect3} -- some display object like a rectangle for example beginFadingArrows(arrows) beginFadingArrows = function(arrows) for i = 1, #arrows do local arrow = arrows[i] timer.performWithDelay(400\*i,function() fadeInArrow(arrow) end) end end fadeInArrow = function(self) self.onComplete = fadeOutArrow if #arrowFadeInTransitions \> 7 then -- clear the transitions and stop them running clearTransitions() end arrowFadeInTransitions[#arrowFadeInTransitions + 1] = transition.to(self,{alpha = 1, time=900, onComplete = self}) end fadeOutArrow = function(self) self.onComplete = fadeInArrow arrowFadeOutTransitions[#arrowFadeOutTransitions + 1] = transition.to(self,{alpha = 0, time=900, onComplete = self}) end clearTransitions = function() for i=#arrowFadeInTransitions,1,-1 do transition.cancel(arrowFadeInTransitions[i]) arrowFadeInTransitions[i]=nil end for i=#arrowFadeOutTransitions,1,-1 do transition.cancel(arrowFadeOutTransitions[i]) arrowFadeOutTransitions[i]=nil end print(#arrowFadeInTransitions) -- sizes are 0 but transitions still run print(#arrowFadeOutTransitions) -- sizes are 0 but transitions still run end