Go.animate [complete_function] calling early, but not if I nest the function (SOLVED)

Hi guys,

having an bit of an issue with go.animate, wondered if anyone had a solution?

So, here’s two pieces of code:

 go.animate(".", "position.y", go.PLAYBACK_ONCE_FORWARD, tar_pos, go.EASING_LINEAR, self.bst_out_dur, 0, 
 		go.animate(".", "position.y", go.PLAYBACK_ONCE_FORWARD, self.position.y, go.EASING_LINEAR, self.bst_rtn_dur, self.bst_hov_dur, 
 			function() 
 				print("returning to neutral")
 				state = neutral 
 			end))

this works perfectly, but if this becomes more complex, I want to break it down into stages and simply pass in a function to [complete_function] parameter of go.animate.

go.animate(".", "position.y", go.PLAYBACK_ONCE_FORWARD, tar_pos, go.EASING_LINEAR, self.bst_out_dur, 0, 
    		go.animate(".", "position.y", go.PLAYBACK_ONCE_FORWARD, self.position.y, go.EASING_LINEAR, self.bst_rtn_dur, self.bst_hov_dur, 
     				animate_boost_done(self)))

If I use this, the same piece of code except I’m passing in a function instead of writing a function to pass as the parameter, it calls the function immediately rather than waiting until the animation is done.

1 Like

Hi Adrian!

It’s just a small error actually, you are actually calling animate_boost_done instead of passing along the function as a parameter. Your second code snippet should look like this instead:

go.animate(".", "position.y", go.PLAYBACK_ONCE_FORWARD, tar_pos, go.EASING_LINEAR, self.bst_out_dur, 0, 
            --animate_boost_in(self))
            go.animate(".", "position.y", go.PLAYBACK_ONCE_FORWARD, self.position.y, go.EASING_LINEAR, self.bst_rtn_dur, self.bst_hov_dur, 
                    animate_boost_done))

See the difference? Instead of passing animate_boost_done(self) as the last parameter you should just pass animate_boost_done. :slight_smile:

2 Likes

Oh! That’s so easy to miss. I’ve not used LUA before so I’d have never seen that.

Thank you! Works perfectly

1 Like

Easy to miss, good luck! :slight_smile: