playing a random sound

Started by Sackboy, Sat 12/01/2013 23:06:50

Previous topic - Next topic

Sackboy

how can i play a random sound with the new sound system? with the old one i could do something like:

Code: AGS
PlaySound(Random(99));


is there something similar?

Khris

What you can do is this:

Code: ags
AudioClip* explosions[3];

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

// play random explosion
  explosions(Random(2)).Play();

Sackboy

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!

Khris

Yes, I'm not aware of an AudioClip array similar to for instance character[].

Crimson Wizard

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.

SMF spam blocked by CleanTalk