Audiostreamplayer not playing music

Godot Version

Godot 4.2

Question

Hey guys. I have this audio system that i built, it refuses to work. The node and its script are auto loaded and always running. As you can see there is a variable called current_music. It gets changed to “menu” “world” or “cliffside”
I know that the changing of the variable works because i have a print statement constantly printing the variables value. It works perfect. But the actual audio never switches. The only music that plays is the “menu” music and It doesnt stop or change i tried stripping the func “play_music” to remove the “!playing” and “.stop” music features but it has nothing to do. It will not work.

I have been struggling with this for a while and i cant seem to figure it out. Help would be appreciated. Thanks!

Are you calling play_music() after changing the value of current_music?

Also, the code could be a lot cleaner with enum.

extends Node

enum {NONE = -1, MENU, WORLD, CLIFFSIDE}
var current_index = NONE

func play_music(new_index):
    if current_index == NONE:
        get_child(new_index).play()
    elif current_index == new_index:
        if not get_child(current_index).playing:
            get_child(current_index).play()
    else:
        get_child(current_index).stop()
        get_child(new_index).play()
    current_index = new_index
1 Like

solved! thank you. i wasn’t calling the function (thought it would be called if it was _Ready)
:man_facepalming:
also thanks for the code advice :+1:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.