Sound_done is not received (SOLVED)

When I play a sound and it ends the script should receive “sound_done” message according to API, but there is no such message.

Repro:

Empty Project.zip (4.7 MB)

function init(self)
	--sound.play("#music", { gain = 1.0 })
	msg.post("#music", "play_sound")
end

function on_message(self, message_id, message, sender)
	print("ALL MSG", message_id)
	if message_id == hash("sound_done") then
		print("DONE")
	end
end

and not even a single message is received :confused:

I ran across this recently. You have to specify play_id for the message to be sent.

 msg.post("#music", "play_sound", {play_id = 1})
3 Likes

Thank you! This instantly solves the problem!

2 minutes support :smiley:

1 Like

There is also sound.play() which can take a callback that will be invoked when the sound has finished playing.

2 Likes

This is even more useful for me! Thanks! I should more frequently check API :smiley: