Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Sackboy on Sat 12/01/2013 23:06:50

Title: playing a random sound
Post by: Sackboy on Sat 12/01/2013 23:06:50
how can i play a random sound with the new sound system? with the old one i could do something like:

Code (AGS) Select
PlaySound(Random(99));

is there something similar?
Title: Re: playing a random sound
Post by: Khris on Sun 13/01/2013 11:23:22
What you can do is this:

Code (ags) Select
AudioClip* explosions[3];

// in game_start or similar
  explosions[0] = aSmallExplosion;
  explosions[1] = aBigExplosion;
  explosions[2] = aHugeExplosion;

// play random explosion
  explosions(Random(2)).Play();
Title: Re: playing a random sound
Post by: Sackboy on Sun 13/01/2013 12:14:20
i see. so you definitely have to construct something by yourself otherwise you can only adress sounds by their names, is this correct? and thanks for the reply!
Title: Re: playing a random sound
Post by: Khris on Sun 13/01/2013 14:11:20
Yes, I'm not aware of an AudioClip array similar to for instance character[].
Title: Re: playing a random sound
Post by: Crimson Wizard on Sun 13/01/2013 14:42:46
This was already discussed some time ago, and it was concluded that the new audio system is made inconvenient for this kind of tasks.

Other than constructing your own array, as Khris suggested, I may point to an option in General Settings - "Enforce new style audio scripting". If you toggle it OFF, you may then use old-style play commands.
I haven't tried this out myself, but I think you may check "Cache File Name" property of audio clip to know its numeric ID.