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