Page 1 of 1

calling sounds from script,. .

Posted: Thu Sep 08, 2011 6:04 pm
by jph_wacheski
Would be very useful to have something like; playSound(Sound, NoteNr, Channel);

Lots of times it would be way better,.. ;)

Posted: Thu Sep 08, 2011 6:51 pm
by Kjell
:)

Would be handy indeed .. but as long as variable types such as Sound / Mesh / Material aren't supported, functions like these won't be possible ( as far as I know ).

However, you can set this up yourself.

Image

So you have a Repeat loop ( after all your logic ) that goes through a Array containing all the sounds that need to be played this frame. Each loop the PlaySound component is updated using something like this.

Code: Select all

int S = SoundRepeat.Iteration;

switch(Sound[S,0])
{
  case 0: Play.Sound = Bass; break;
  case 1: Play.Sound = Kick; break;
}

Play.NoteNr = Sound[S,1];
Play.Channel = Sound[S,2];
Then your function can then look something like this.

Code: Select all

void playSound(int Sound, float Note, int Channel)
{
  int S = SoundSize;

  Sound[S,0] = Sound;
  Sound[S,1] = Note;
  Sound[S,2] = Channel;

  SoundSize++;
}
K