# Go.Animate callback doesn't work as documentation says (SOLVED)

**URL:** <https://forum.defold.com/t/go-animate-callback-doesnt-work-as-documentation-says-solved/9810>\
**Category:** Questions\
**Created:** [July 14, 2017, 7:18am UTC](https://forum.defold.com/t/go-animate-callback-doesnt-work-as-documentation-says-solved/9810 "2017-07-14T07:18:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pantarou8](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pantarou8/32/8030_2.png) [@pantarou8](https://forum.defold.com/u/pantarou8)\
**Post date:** [July 14, 2017, 7:18am UTC](https://forum.defold.com/t/go-animate-callback-doesnt-work-as-documentation-says-solved/9810/1 "2017-07-14T07:18:01Z")

</div>

Sorry for my crazy English.

## Description

* * *

I’m trying to make a simple sequence handling module.  
that sequence system works almost exactly the same with [this](https://forum.defold.com/t/big-list-of-defold-pro-tips/1519/10) post (thanks to @Pkeod )  
when we call the RunEvent(script) function from the outside of the module, It loads up the script as a coroutine,  
and coroutine reads and executes functions one by one.

I’ve touched several programming languages, but I’m almost new to Lua.

## Problem

* * *

> **Simplified Source code**
>
> ```lua
> function event.move(_target,_pos,_duration)
> print("[EVENT] Event_Move called. ")
> --local pos = go.get_position(_target) + _pos
> go.animate(_target, --url
> "position.x", --property
> go.PLAYBACK_ONCE_FORWARD, --playback
> 10, --To
> go.EASING_LINEAR, --easing
> _duration, --duration
> 0, --delay
> function() --callbck
> coroutine.resume(event.co)
> end)
>  
> coroutine.yield()
> end
> 
> ```

_Intended work_ :

> When coroutine called “event.move” function (it animates object which given by arguments),  
> It animates properly, and when it finished,  
> calls an anonymous function that resumes the coroutine.

_What Actually Happened_ :

> When coroutine called “event.move” function, It animates properly,  
> **But it never calls an anonymous function, and it ends.**

## Tried list

* * *

1. I changed  
`function() coroutine.resume(event.co) end`  
to  
`function() print("a") end`

- it prints nothing

1. I changed the whole  
`function() coroutine.resume(event.co) end`  
to  
`print("test")`

- It immediately prints the text “test”. Didn’t wait until the animation ends.

---

<div class="post-metadata">

**Author:** ![pantarou8](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pantarou8/32/8030_2.png) [@pantarou8](https://forum.defold.com/u/pantarou8)\
**Post date:** [July 14, 2017, 8:16am UTC](https://forum.defold.com/t/go-animate-callback-doesnt-work-as-documentation-says-solved/9810/2 "2017-07-14T08:16:59Z")

</div>

I’ve solved this problem on my own.

What I did is:

I tried to reproduce this problem with the minimal amount of source code, then I successfully reproduced with this code.

```lua
--reproduce1.script attached to reproduce1.go

event = require("/main/reproduce/reproduce")

function init(self)
	local co = coroutine.create(
	function()
		event.move("/reproduce_2",2)
	end
	)
	coroutine.resume(co)

	go.delete()
end

```

```lua

--/main/reproduce/reproduce.lua
event = {}

function event.move(target,_duration)
	print("Event_move")
	go.animate(target,"position.x",go.PLAYBACK_ONCE_FORWARD,10,go.EASING_LINEAR,1,0,function() print("Reproduce") end)
	coroutine.yield()	
end

return event

```

and this problem is the same thing with this post

> [@Callback function in go creating by factory and use go.animate bug](http://forum.defold.com/t/callback-function-in-go-creating-by-factory-and-use-go-animate-bug/3702):
>
> local function callback () print "hi" end ...... function init(self) local obj = factory.create("#factory", go.get\_position()) go.animate(obj, "scale", go.PLAYBACK\_ONCE\_FORWARD, self.end\_scale, go.EASY\_LINEAR, self.live\_time, 0, callback) go.delete() end callback not called

thanks for helping and sorry for timewasting.

---

<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:** [July 14, 2017, 8:38am UTC](https://forum.defold.com/t/go-animate-callback-doesnt-work-as-documentation-says-solved/9810/3 "2017-07-14T08:38:34Z")

</div>

Good to hear that you solved the problem on your own!
