Solarus-Games English Forum

Solarus => Development => Topic started by: Starlock on January 18, 2018, 09:52:14 PM

Title: Issue with playing music
Post by: Starlock on January 18, 2018, 09:52:14 PM
Whenever I go from one map to another, the song will restart despite it being the same song. I'm calling the sol.audio.play_music(music_id, [action]) from inside of the map:on_started() since there are three different songs that can play depending on your progress in the game. What do I need to do to stop the music from restarting?
Title: Re: Issue with playing music
Post by: Diarandor on January 18, 2018, 10:14:27 PM
Get the current music in a variable. Then you can do something like this:

if current_music ~= music_id then
  sol.audio.play_music(music_id, [action])
end
Title: Re: Issue with playing music
Post by: Starlock on January 19, 2018, 12:04:27 AM
That didn't seem to work. The music still restarts whenever you go from one map to another. Isn't it not supposed to restart regardless if it's the same song, like what it says on the wiki?

"If you set the music name to the same music that is already playing, or to the special value "same", then this function does nothing: the music keeps playing (it does not restart) and the second parameter is ignored."
Title: Re: Issue with playing music
Post by: Christopho on January 19, 2018, 12:36:07 AM
That is true, but I guess maybe you put no music in the map properties (in the left panel of the map editor). So the music stops when the map starts, and then your code starts it again.
Set the music to the one you want (or to "Same") in the map properties panel.