sound.play currently requires a string to be passed ( the name of the sound slot ).
I wanted a generic way to just play the first sound attached to the sound. If the user renamed the sound ( which they are taught to do with all assets, to make them more meaningful ), then just doing this doesn’t work.
entity.sound.play(“Slot 1”);
It would be great if sound.play allowed for an index, so this would work…
entity.sound.play(0);
…and to extend that further, have entity.sound.play() use by default the first sound slot, if it exists.
For anyone looking for an alternative solution, the code below works to play the first
entity.sound.play(Object.keys(entity.sound.slots)[0]);
This could be a case where, if many users might only attach a sound to an object with one sound clip, having the ability to just call sound.play() to play that one sound would make life a bit easier.