Author Topic: Looping music with a non-looping intro  (Read 301 times)

Wulface

  • Newbie
  • *
  • Posts: 2
    • View Profile
Looping music with a non-looping intro
« on: March 21, 2017, 09:02:02 pm »
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
  1. function map:on_started()
  2.   sol.audio.play_music("orion_start", sol.audio.play_music("orion", true))
  3.  

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!

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1053
    • View Profile
Re: Looping music with a non-looping intro
« Reply #1 on: March 21, 2017, 09:27:20 pm »
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
  1. sol.audio.play_music("orion_start", function()
  2.   sol.audio.play_music("orion", true)
  3. end)
  4.  
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

Wulface

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Looping music with a non-looping intro
« Reply #2 on: March 21, 2017, 09:28:27 pm »
That's awesome!
Thank you very much :)