Can onComplete in transition.to cause Recursion?

If I do this:

local function foo() -- something happens here transition.to (someObj, {time=1000, x=100, onComplete=foo }) end

…is that a recursive call? I’m thinking it’s not, that onComplete makes the call after foo has returned, but I need to make sure.

 Jay

It’s not a recursive function, but yes - the transition will be re-fired after the first one completes. You might find that the parameter iterations=0 might cause infinite looping, if that’s what you want (but I haven’t checked.)

Gotcha: I think the function ‘foo’ needs to be declared as a variable before the function is created because within the function the function name has not yet been constructed, which means the onComplete=foo will evaluate to onComplete=nil, and so the re-fire will not happen. You would want something like:

local foo foo = function() -- something happens here transition.to (someObj, {time=1000, x=100, onComplete=foo }) end

Thanks, Horace. I hadn’t run into the “chicken and egg” problem because my IDE automatically creates forward declarations for all my functions.

I’ve been running into a stack overflow issue and am just trying to make sure it’s not the onComplete in the transition.to that’s the problem.

 Jay

Does the overflow still happen if the function is called on a timer instead of onComplete?

It’s not a recursive function, but yes - the transition will be re-fired after the first one completes. You might find that the parameter iterations=0 might cause infinite looping, if that’s what you want (but I haven’t checked.)

Gotcha: I think the function ‘foo’ needs to be declared as a variable before the function is created because within the function the function name has not yet been constructed, which means the onComplete=foo will evaluate to onComplete=nil, and so the re-fire will not happen. You would want something like:

local foo foo = function() -- something happens here transition.to (someObj, {time=1000, x=100, onComplete=foo }) end

Thanks, Horace. I hadn’t run into the “chicken and egg” problem because my IDE automatically creates forward declarations for all my functions.

I’ve been running into a stack overflow issue and am just trying to make sure it’s not the onComplete in the transition.to that’s the problem.

 Jay

Does the overflow still happen if the function is called on a timer instead of onComplete?