Author Topic: Issue with playing music  (Read 782 times)

Starlock

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Issue with playing music
« 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?

Diarandor

  • Hero Member
  • *****
  • Posts: 1053
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Issue with playing music
« Reply #1 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
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

Starlock

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Issue with playing music
« Reply #2 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."

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1177
    • View Profile
Re: Issue with playing music
« Reply #3 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.