Hello!! Im trying to put some music at a specific point in one of my scenes, but when i tried importing it as an mp3, i kept running into problems of it not starting in gdscript.
It’ll only start if i have it set on autoplay, but i need to delay it a little bit, so i was going to try and play it in gdscript. When i had the code at the bottom, though (which im very unsure about, but a few tutorials I saw said to use it, along with hovering over the ‘play’ inspector thing itself), it just wont play. I also tried importing it as a wav file to see if that was, on the off chance, the problem, but it gave me so many different errors (that all amounted to “can not import/read this”) that i couldn’t post them here without it being unreadable.
That means the if statement is never true in the ready function. The ready function only runs a single time so even if you change that variable in the future, it’ll never be executed again.
play() will restart the audio stream, by using it in _process you are restarting the song every frame. You could check if not playing: play(), but that sounds kind of wild. Maybe you should find a way to reference this audio stream player and play it through your global script?
So this is only a mp3 file, not an audio stream player
If this was an audio stream player you would run into the same issue as before, because this code is still in _process and still re-starting what would be an audio player every frame.
What I’d recommend is giving your Global an AudioStreamPlayer node, then using a new function to play “daisy_bell” instead of using a single variable and checking if it’s set.
# global.gd
extends Node
# Make sure to add an AudioStreamPlayer as a child. This example expects the name "MusicPlayer"
@onready var music_player: AudioStreamPlayer = $MusicPlayer
func play_daisy_bell() -> void:
music_player.stream = load("res://Art/daisy_bell.mp3")
music_player.play()
I don’t know how your game code works, but instead of setting Global.daisybell = true I believe you can swap it out for Global.play_daisy_bell()
thank you!! I got it working (i connected it to the main node instead of globals though; i have dialogue in the scene, so im now using that to call the diasybell function). Thank you so much!!!