How can I make it so that if the music is playing, it will not be played from the beginning, otherwise, if it is not playing, it will be played? I will say that I tried to make this code:
func play_music():
if not bg_music.is_playing():
bg_music.play()
elif bg_music.is_playing():
return
I use the following sort of function in my sound manager code, this is assuming you’re using an Audiostream player created in code or part of your scene.
func play_music() -> void:
if not bg_music.playing:
bg_music.play()
Can you show your scene and errors. If bg_music is the name then prefix it with a $ symbol to locate in your scene or control drag it into your script to get an @onready name in the script.
func play_music() -> void:
if not $bg_music.playing:
$bg_music.play()
Yes, the scene is global so that the music plays not in the scene but in the game, and also the play_music() function is played in the _ready() function in the level script
extends Node
var keys : int = 0
var room : int = 1
var deaths : int = 0
var player = self
func _process(delta: float) -> void:
if Input.is_action_just_pressed("f11"):
if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_WINDOWED:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
else:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)