# Go animation return function

**URL:** <https://forum.defold.com/t/go-animation-return-function/11461>\
**Category:** Questions\
**Created:** [September 12, 2017, 6:28pm UTC](https://forum.defold.com/t/go-animation-return-function/11461 "2017-09-12T18:28:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarnumius](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@tarnumius](https://forum.defold.com/u/tarnumius)\
**Post date:** [September 12, 2017, 6:28pm UTC](https://forum.defold.com/t/go-animation-return-function/11461/1 "2017-09-12T18:28:48Z")

</div>

Hello all.

Last parameter in go.animation it callback function. In my project sometimes it callback function not call. I think it because animation not change position object. I think right? It happenend when GO start next animation very fast and previous animation not finished. May be you know good method resolve problem.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [September 13, 2017, 4:12am UTC](https://forum.defold.com/t/go-animation-return-function/11461/2 "2017-09-13T04:12:30Z")

</div>

> [@tarnumius](#):
>
> It happenend when GO start next animation very fast and previous animation not finished.

The callback function will only be called if the animation is allowed to finish before you trigger a new animation. An animation that is cancelled (go.cancel\_animation()) or replaced by a new animation (go.animate()) will not trigger the callback. And obviously an animation that has a playback of go.PLAYBACK\_LOOP\_\* will never finish and invoke the callback function either.

---

<div class="post-metadata">

**Author:** ![tarnumius](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@tarnumius](https://forum.defold.com/u/tarnumius)\
**Post date:** [September 13, 2017, 7:07am UTC](https://forum.defold.com/t/go-animation-return-function/11461/3 "2017-09-13T07:07:31Z")

</div>

Thank you.

I have fast change incoming messages for animation parameters and go.animation() - replaced and not finished. I think about change logic, but it may be problem.

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [September 13, 2017, 7:26am UTC](https://forum.defold.com/t/go-animation-return-function/11461/4 "2017-09-13T07:26:17Z")

</div>

I have ran into similar problems at a few occasions where I’ve had multiple animations running on top of each other. Try checking for that.

---

<div class="post-metadata">

**Author:** ![tarnumius](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@tarnumius](https://forum.defold.com/u/tarnumius)\
**Post date:** [September 13, 2017, 7:55am UTC](https://forum.defold.com/t/go-animation-return-function/11461/5 "2017-09-13T07:55:25Z")

</div>

Yeah I have same.

Logic example:  
Every 2-5 sec recieve incoming message, after receive - start animation. If previous animation not finished, next logic not working ☹

```lua
function y_done(self, url, property)		
	local target_x = 13
	for i=1,10 do							
		if i < 10 then			
			go.animate("/psychoState/psychoStateBarSingle"..tostring(i), "position.x", go.PLAYBACK_ONCE_FORWARD, target_x, go.EASING_INOUTBACK, 1, 0)																			
		else
			go.animate("/psychoState/psychoStateBarSingle"..tostring(i), "position.x", go.PLAYBACK_ONCE_FORWARD, target_x, go.EASING_INOUTBACK, 1, 0, x_done)			
		end	
		go.animate("/psychoState/psychoStateBarSingleEmpty"..tostring(i), "position.x", go.PLAYBACK_ONCE_FORWARD, target_x, go.EASING_INOUTBACK, 1, 0)		
	end			
end	

function x_done(self, url, property)						
--something code
end

function on_message(self, message_id, message, sender)
if message_id == hash("change_state") then
		self.newChange = true		
		if type(message.stateParamsChange) == "table" then			
			self.stateParamsChange[#self.stateParamsChange+1] = message.stateParamsChange
		else
			self.stateParamsChange = {}
		end
       go.animate("/psychoState/psychoPortraitState", "position.y", go.PLAYBACK_ONCE_FORWARD, 186, go.EASING_INOUTBACK, 0.5, 0, y_done)
	end
end

```

Animation in on\_mesage function work good(it ended first) and y\_done function ended everytime, but animation in x\_done function sometimes not ended and x\_done not executed ☹
