How do I make my "music list" pick a new song after ending?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Spafnar

Hello, in my newgame function, I have the following script which allows me to utilize an array and have the engine randomly select a song and play it:

var _music_list = (["the songs i saved the paths for"])
var song = _music_list[randi() % _music_list.size()]
$AudioStreamPlayer.stream = load(song)
$AudioStreamPlayer.play()

The issue is that after playing for long enough, after the song ends, it is just quiet. I orginally had added

if $AudioStreamPlayer.stop() 
              $AudioStreamPlayer.stream = load(song)
              $AudioStreamPlayer.play()

I know that the stream is never manually told to stop so I didn’t think this would work, nevertheless, it still remains quiet, but I dont get any warnings or errors. Does anyone know if there is a code that would allow the engine to randomly select another song after the current one ends?

:bust_in_silhouette: Reply From: Spafnar

Aha, nevermind, I just realized the AudioStreamPlayer has a “finished” signal I could connect. I leave this up if anyone else is curious.

Another Edit: Just kidding I still need help. It works like I want it to now, but because my game over function tells the streamplayer to stop, after it gets to main menu it plays a song and it overlaps with the main menu music. Is there a way to only have it load a new song to play once done only while the game is playing

If you’re using a variable for the game state such as “var playing = true” you can use that for playing/stopping the music. So if playing is true, the music keeps picking new songs after one is done. If playing is false (in the menu screen), the music list stops and you can just play the menu music.

Arakir | 2022-04-07 00:23