How do i stop this?

So i need to stop this at a point but im not sure how…

function moveHi1() transition.to( hi,{time=800, alpha = 0.5, onComplete=moveHi} ) end function moveHi() transition.to( hi,{time=800, alpha = 1, onComplete=moveHi1} ) end moveHi() \<-- stop this..

Thanks!

When do you want it to stop?

local maxPasses = 3 local count = 0 local moveHi1 local moveHi2 moveHi1 = function() transition.to( hi,{time=800, alpha = 0.5, onComplete=moveHi2} ) end moveHi2 = function() count = count + 1 if( count \>= maxPasses ) then return end transition.to( hi,{time=800, alpha = 1, onComplete=moveHi1} ) end moveHi2()

Well on collision i want the moveHi() to stop… is there an easier way than the one you posted ?

So is there no easier way to remove it?

Sure do this:

local moveHi1 local moveHi2 moveHi1 = function( obj ) obj.onComplete = moveHi2 transition.to( obj,{time=800, alpha = 0.5, onComplete = obj } ) end moveHi2 = function( obj ) obj.onComplete = moveHi1 transition.to( obj,{time=800, alpha = 1, onComplete = obj } ) end hi.collision = function( self, event ) if( event.phase == "began" ) self.onComplete = nil -- CLEAR ON COMPLETE (BEFORE CANCEL) transition.cancel( self ) -- CANCEL CURRENT TRANSITION display.remove( self ) end return true end hi:addEventListen( "collision" ) moveHi2( hi )

Does the same code go for if i want to stop the transition when i touch the object?

So what i tried was to cancel the transitions and it works but the function loops keep going…

I fixed it, If you want the solution you can ask and ill take the time to post the code and what i did.

Thanks for the help!

Did you remember to nil the call back before canceling?  That was a critical step.

Regardless, yes please post your solution so others can see it.

Cheers,

Ed

Hey so heres the code i used…

 local transOne local transTwo local function touchToStop(event) if event.phase == "ended" then transition.cancel(transTwo) -- canceled these two transitions transition.cancel(transOne) -- which actually stopped the fucntions from firing further.. hi:removeEventListener( "touch", touchToStop ) end return true end Runtime:addEventListener( "touch", touchToStop ) function moveHi1() transOne = transition.to( hi,{time=800, alpha = 0.5, onComplete=moveHi} ) end function moveHi() transTwo = transition.to( hi,{time=800, alpha = 1, onComplete=moveHi1} ) end moveHiTimerOne = timer.performWithDelay( 1, moveHi, 1 ) -- made a 1 milisecond function that only fires once..

I commented out some of the parts…

BTW everything is working so i dont think i need the nill the call back before cancelling? If i do how do i do so?..

Thanks for all -SonicX278!

I would consider using tags…

function moveHi1() transition.to( hi,{time=800, tag="moveHi" alpha = 0.5, onComplete=moveHi} ) end function moveHi() transition.to( hi,{time=800, tag="moveHi", alpha = 1, onComplete=moveHi1} ) end moveHi() \<-- stop this..

then

transition.cancel("moveHi")

Rob

Ohh thanks Rob! Never knew there was something like that(tags)

Thanks Again!

Good suggestion Rob.  That is a much cleaner and simpler solution.

When do you want it to stop?

local maxPasses = 3 local count = 0 local moveHi1 local moveHi2 moveHi1 = function() transition.to( hi,{time=800, alpha = 0.5, onComplete=moveHi2} ) end moveHi2 = function() count = count + 1 if( count \>= maxPasses ) then return end transition.to( hi,{time=800, alpha = 1, onComplete=moveHi1} ) end moveHi2()

Well on collision i want the moveHi() to stop… is there an easier way than the one you posted ?

So is there no easier way to remove it?

Sure do this:

local moveHi1 local moveHi2 moveHi1 = function( obj ) obj.onComplete = moveHi2 transition.to( obj,{time=800, alpha = 0.5, onComplete = obj } ) end moveHi2 = function( obj ) obj.onComplete = moveHi1 transition.to( obj,{time=800, alpha = 1, onComplete = obj } ) end hi.collision = function( self, event ) if( event.phase == "began" ) self.onComplete = nil -- CLEAR ON COMPLETE (BEFORE CANCEL) transition.cancel( self ) -- CANCEL CURRENT TRANSITION display.remove( self ) end return true end hi:addEventListen( "collision" ) moveHi2( hi )

Does the same code go for if i want to stop the transition when i touch the object?

So what i tried was to cancel the transitions and it works but the function loops keep going…

I fixed it, If you want the solution you can ask and ill take the time to post the code and what i did.

Thanks for the help!