The complete_function should be either an anonymous function or a reference to another function within the scope of the current script.
An anonymous function is like
function(self, message_id, message, sender)
-- do something
end
This defines some code without yet running it. You’ll see it as useful concept in many other areas of the API.
So with play sound you can do (and note that it’s complete_function not complete_function() which would run the code immediately upon running the sound.play)
local function complete_function(self, message_id, message, sender)
-- do something when sound ends
end
sound.play("#sound", { delay = 1, gain = 0.5, pan = -1.0 } , complete_function)
or
sound.play("#sound", { delay = 1, gain = 0.5, pan = -1.0 } , function (self, message_id, message, sender)
-- do something when sound ends
end)
And then in either case that code can be ran after the sound completes playing.
You have another option to check the on_message for the script which called the sound.play() and there you should get the sound_done message when the sound stops playing.