0 votes

So I have a AudioStreamPlayer, that has script that iterates through a folder and pulls all the wav files and stores them in an array and then a method to play one of them at random and another to skip to the next song. When I do this in the editor it works with no issues or errors, but as soon as I export it to a runnable windows exe it fails to retrieve any of the files and shows a error of
Invalid get index '0' (on base: 'Array').
At: res://World/MusicPlayer.gdc:32

this is the code below im using

extends AudioStreamPlayer
var music_list = []

func ready():

func input(event):
if event.is

func getallmusic():
var dir = Directory.new()

while true:
    var file = dir.get_next()
    if file == "":
        #no more files
    elif not file.begins_with(".") && !file.ends_with(".import"):
        music_list.append(load("res://Assets/Music/" + file))


func picksong():
var list
len = musiclist.size()
var i = randi() % (list
len - 1)
stream = musiclist[i]

func onMusicPlayerfinished():

Godot version 3.3.stable.mono
in Engine by (21 points)

1 Answer

0 votes

There are two things to check for here:

  1. Add *.ogg,*.mp3,*.wav to the non-resource export filter in the Export dialog. This ensures the audio files you're trying to load at run-time are present in the PCK file.
  2. Check the file casing in the file names. Windows is not case-sensitive but the virtual PCK filesystem (which is used in export projects) is case-sensitive. I recommend using lowercase characters only in file names to prevent problems like these from cropping up.
by (10,471 points)

if the music file name has spaces in it could that cause issues too?

Spaces should be fine, but it's best to avoid them if possible.

I'm exporting all files and it appears that all files are being called correctly

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.