How to pause code until flipbook animation is done playing?

Hello everyone, I’m a complete Defold newbie so my code might be a bit ugly.. In my menu, I have a button that you click to start the game, loading in a new collection. I would like the button to finish playing an animation after you click it before it loads in the new collection. Is that possible? I’ve tried using anim_callback in my gui script based off other people’s code I’ve seen, but it doesn’t work for me, so I think I’m doing it wrong? The loading in new collection works fine.

local function anim_callback(self.node)
end

function on_input(self, action_id, action)
    if(action_id == hash("touch") and action.pressed == true) then
          if gui.pick_node(gui.get_node("golvl1"), action.x, action.y) then
          local golvl1 = guiget_node("golvl1")
         gui.set_texture(golvl1, "button")
         gui.play_flipbook(golvl1, "button1anim", anim_callback)
               if gui.pick_node(gui.get_node("golvl1"), action.x, action.y) then
                      msg.post("proxy:/controller#controller", "show_lvl1")
               end
         end
     end
end

What doesn’t work exactly?

Also note that your callback function is empty, i.e. it’s not doing anything at all.

On the on_message function, check for animation_done message. After receiving it, call the loading new collection.
Note that you will receive the message only if the animation is not looped and actually ends

Ah I was wondering if that was part of it :sweat_smile: but it was like that in other examples I saw. It is indeed that function that’s not doing anything. Once I filled it out, it started working. All solved!