Sounds

  • Hi I was just wondering if there is a way to place sound files in some sort of array, or have a function to play random sound files?

  • Bump

  • Most people tend to avoid sound questions on this site for some reason. I don't, because I'm a sound guy myself.

    However, I don't know the answer because I haven't studied arrays yet. It's on my to-do list.

    For functions, you can always put sound event in a function. However, for random sounds, check out these search results...

    https://www.scirra.com/forum/search?q=random+sounds.

  • Thank you so much, I appreciate the link. I tried out Yann's example using "choose" and it worked like a charm. I now need to do a bit of poking around to find out how to keep a chosen sound file from being chosen twice in a row. I think I've seen it applied to sprite creation, so probably works for sounds too.

  • I don't remember what is my example but you can keep a list of sound, and pick randomly without repetition like that:

    +System: On Start of layout
       -> Array: set size to (0,1,1)
       -> Array: push back soundA.wav on X axis
       -> Array: push back soundB.wav on X axis
       -> Array: push back soundC.wav on X axis
       -> Array: push back soundD.wav on X axis
       -> ...
    
    +On whatever
       local number randomIndex = 0
       -> System: randomIndex = floor(random(Array.Width))
       -> Audio: play sound Array.At(randomIndex)
       -> Array: delete at index randomIndex)

    The delete function of the array object delete the value at the index and shrink the array by 1 to fill the gap. So the Array.Width will decrease until you played every sound in the list.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Wow Awesome Yann!

    I'll give it a try.

  • For your soundplay list. I'm not because I haven't played with sound much, but I assumed that sound files had both a name(unique) and tag(shared?). So that if you play by tag it would then just play all of them with the tag.

    I guess the best way is to experiment with that

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)