Looping music with a non-looping intro

Started by Wulface, March 21, 2017, 09:02:02 PM

Previous topic - Next topic
Hey there!

I am currently working on my Zelda starter pack, using Solarus.
I am still learning the ropes of Lua programming and I'm facing this situation, hoping I could get some help!  :)

I use custom OGG musics, and some are separated in two files. For example, in Orion village, the game should play the content of "orion_start.OGG", then loop "orion.OGG".
This is what I tried :
Code ( lua) Select

function map:on_started()
  sol.audio.play_music("orion_start", sol.audio.play_music("orion", true))


I see that there is an error because even thought the console is not giving me any error code, only orion_start.OGG is looping.
Understanding this principle on functions will help me alot in my comprehension of the Lua language, I hope I can get some help!

Thank you all!

Hi,
You called sol.audio.play_music() instead of passing a value of type function. Classic error if you are not very used to functions as first-order values :P
Code (lua) Select

sol.audio.play_music("orion_start", function()
  sol.audio.play_music("orion", true)
end)

This should work.

However, since Solarus 1.5 there is a better solution. You can keep a single file with metadata that tells Solarus where to loop. More exactly, we use the same metadata convention as RPG Maker.
You can do like explained here: https://forums.rpgmakerweb.com/index.php?threads/make-looping-bgm-part-1-ogg-vorbis.10987/.
Just LOOPSTART is enough. LOOPLENGTH and LOOPEND and not needed. For more details see the doc here:
http://www.solarus-games.org/doc/1.5/quest_musics.html