Strange problem with using two transform.to() call.

Hi,

I defined  a function for one of my tables as:

NetObject.Disable = function (self) timer.performWithDelay(50, function() self.x = 50 end, 1) end

Nothing fancy, right? just change it’s position so I can confirm it’s working.

Then later on, I set collision handler of that object as:

local function onNetObjectCollision(self, event) transition.to (self, {time=1000, alpha=0.20, xScale=3.5, yScale=3.5, transition=easing.inOutQuad, onComplete = self:Disable() } ) --narm removeThisFoodObjectFromTheWholeGameProperly(event.other) end

Problem is that, transition.to calls the onComplete call back function before actually completing it’s job, which was to change alpha to .2 and increase scale in span of 1000ms.

So in other words, instead of first changing alpha and scaling, it first moves the object then starts to do the alpha and scale jobs.

What am I missing here?

Thanks.

I solved it suddenly by changing this:

transition.to (self, {50, time=1000, alpha=0.20, xScale=3.5, yScale=3.5, transition=easing.inOutQuad, onComplete = self:Disable() } )

to:

transition.to (self, {time=200, alpha=0.20, xScale=3.5, yScale=3.5, transition=easing.inOutQuad, onComplete = self.Disable } ) --narm

(Note the onComplete difference).

I’m not 100% sure why that worked, I wanted to make sure that when I get to onComplete, I have access to the “self” property, so I passed self:Disable() with colon but now that I pass self.Disable, it still has the self parameter with it.

I n transition.to()'s documentation page I found this:

params.onComplete (optional) Listener. A listener called after the tween completes. When invoked, the listener is passed target instead of an Event.

I think it’s related to my question, but not sure.

The problem in your original transition is that you put self:Disable(). Whenever you put the () after a function call, that function gets called immediately regardless of where it’s at. Instead you should put onComplete = self:Disable

Thanks JonPM for the explanation.

Would you, or anyone else, please explain why setting self.Disable instead of self:Disable also gave me “self” at the Disable? Isn’t having self the effect of calling a function with colon?

I solved it suddenly by changing this:

transition.to (self, {50, time=1000, alpha=0.20, xScale=3.5, yScale=3.5, transition=easing.inOutQuad, onComplete = self:Disable() } )

to:

transition.to (self, {time=200, alpha=0.20, xScale=3.5, yScale=3.5, transition=easing.inOutQuad, onComplete = self.Disable } ) --narm

(Note the onComplete difference).

I’m not 100% sure why that worked, I wanted to make sure that when I get to onComplete, I have access to the “self” property, so I passed self:Disable() with colon but now that I pass self.Disable, it still has the self parameter with it.

I n transition.to()'s documentation page I found this:

params.onComplete (optional) Listener. A listener called after the tween completes. When invoked, the listener is passed target instead of an Event.

I think it’s related to my question, but not sure.

The problem in your original transition is that you put self:Disable(). Whenever you put the () after a function call, that function gets called immediately regardless of where it’s at. Instead you should put onComplete = self:Disable

Thanks JonPM for the explanation.

Would you, or anyone else, please explain why setting self.Disable instead of self:Disable also gave me “self” at the Disable? Isn’t having self the effect of calling a function with colon?