Animation complete function (SOLVED)

how can i call the function “animate_end” in this code when the my animation in init is complete? i read the manual but i dont understand how this functions works

function init(self)
	go.animate("#sprite", "tint.w", go.PLAYBACK_ONCE_BACKWARD, 0, go.EASING_INOUTSINE, 5, animate_end())
end

function final(self)
	-- Add finalization code here
	-- Remove this function if not needed
end

function update(self, dt)
	
	-- Add update code here
	-- Remove this function if not needed
end

function on_message(self, message_id, message, sender)
	-- Add message-handling code here
	-- Remove this function if not needed
end

function on_input(self, action_id, action)
	-- Add input-handling code here
	-- Remove this function if not needed
end

function on_reload(self)
	-- Add reload-handling code here
	-- Remove this function if not needed
end

function animate_end()
	print('end')
end

There’s need to be fixed, ’ animate_end()’ is a function call without parenthss, just ‘animate_end’. And before that function.

1 Like

Also it’s possible for the function to be anonymous.

go.animate(".", "position.x", go.PLAYBACK_ONCE_BACKWARD, 0, go.EASING_INOUTSINE, 5, 0,  function() print("hello") end)

Found another issue you need another number or nil before the function like in above. The delay value comes before the callback function.

1 Like

Yo, i missed read about playback position on param between go.animate() and gui.animate()
I thought it was in delay param.

1 Like

This will call the function, not pass it as an argument.

It’s also good if you make a habit of creating local functions instead of global:

local function animate_end()
end

Note that with local functions the order of declaration is important. In your case the animate_end function needs to be declared before the call to go.animate(). But as other’s have pointed out, anonymous functions is usually how its done.

1 Like

Thanks for help me!

It’s working now, thanks for the help!

if I use it as a local function it is not called, I tried to use it and it did not work, only if it is not local, but thanks for you reply !

Remember that if you declare a function local it needs to be above the call in the source file, according to Lua’s scoping rules. See Lua programming in Defold

2 Likes