x


Trouble loading sounds into array

Hey everyone. I'm trying to load a handful of sound files into an array via Javascript but the zeroth spot refuses to cooperate. I have all the sound file's names in a string array and load the audio clip array using a for loop. Initially I thought the problem was the for loop but tried manually loading individual slots and found that all besides the very first slot will load via the script. If I try dragging and dropping a file from the resources folder into the array during runtime it works fine but players obviously can't do that. Has anybody ever run into a problem like this before or does anybody have a possible solution?

Here's basically what the JS looks like;

var sound  = new AudioClip[6];
var sfile : String[] = ["Chime_01","Fireball_01","Roar_01","Snarl_01","Stomp_01","Sword_01"];

then later in Start()...

for ( var j : int = 0; j < 6; j++){
    sound[j] = Resources.Load(sfile[j]);

Then in inspector I always see this...

Sound

size 6

Element 0 None(Audio Clip)

Element 1 Fireball_01

Element 2 Roar_01

Element 3 Snarl_01

Element 4 Stomp_01

Element 5 Sword_01

bizarre... Anyways thanks for your help in advance.

more ▼

asked Jun 06 '11 at 11:56 PM

Catsby gravatar image

Catsby
26 7 7 12

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I've tried the same thing, but it worked for me. I had problems initially because my sound files were in the wrong folder, so all elements of sound[] became empty - but I had no error messages. When I finnally put the files in the right folder, it worked for all elements of the array. Could the first file name of your list be misspelled, or in a folder other than Resources?

more ▼

answered Jun 07 '11 at 02:36 AM

aldonaletto gravatar image

aldonaletto
41.3k 16 42 195

Since entry one to five are placed in slot one to five, the only obvious reason for it 'skipping' entry zero is because the name is indeed misspelled or it's not in the correct folder. I'm assuming you have a closing } but you just didn't copy/paste it.

Jun 07 '11 at 02:42 AM Joshua

You know, I thought so too and tried renaming the file and moving it around but that didn't seem to work. It does the same thing regardless of the file I'm trying to put in it. I'm going to try renaming the array and see if that fixes it or not.

Jun 07 '11 at 02:44 AM Catsby

I also just straight up tried sound[0] = Resources.Load(filename here); and had the same problem. so weird...

Jun 07 '11 at 02:47 AM Catsby

So you're saying that if, in the sfile:String[] array you switch "Chime_1" and "Fireball_1" it will still skip over entry zero in the sound:AudioClip[] array and not the first entry which would be expected if it couldn't find "Chime_1"?

Jun 07 '11 at 02:48 AM Joshua

That is correct. I'm about to just delete the audioclip array and re declare it with a different name.

Jun 07 '11 at 02:53 AM Catsby
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3447
x1356
x523
x23

asked: Jun 06 '11 at 11:56 PM

Seen: 1140 times

Last Updated: Jun 07 '11 at 03:14 AM