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

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 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
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.

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.

--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


--/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

thanks for helping and sorry for timewasting.

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