How do I (How to generate a random sound? ... RESOLVED)

1 favourites
  • 12 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template for top-down view games)
  • Hello guys I'm riding an application and I have a question that might be simple, the question is as follows:

    How do I generate a random sound of several whenever loaded layout?

    I thank all who try to help me in any way.

    Rony Sueliton

  • Creat a global variable "Randomeaudio"- set condition as on every loaded layout Choose(1,2,3,4,5)

    then add another condition

    if Randomeaudio is equal to 1 play sound 1

    if Randomeaudio is equal to 2 play sound 2

    if Randomeaudio is equal to 3 play sound 3

    if Randomeaudio is equal to 4 play sound 4

    if Randomeaudio is equal to 5 play sound 5

    and so as per number of audio files you want to play!

    hope i answered your question!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Could someone give some more opinion? For yet unable to fashion the "iGamersBox" stated in its reply.

    I'm always trying, but as I am new to construct2, seek always learn more.

    I thank you all.

  • I tried and could not do it does not run the sound!

    Can anyone help?

  • There is a difference between Random and Choose expression! When you use random 1,2,3 then system can pick random 1.5, 2.6 or 2.9 as random thus failing the condition sound equal to 1 or 2.

    use choose instead of random and it will work ex "set sound to choose(1,2,3,4,5,6,7)"

    this will do trick!

  • It worked, but the problem is that it does not run the sound more than 7 times, should this happen many times as necessary to press the button.

  • I'm a beginner also, but I had a similar need. I created an array containing all the names of my sounds (Text). Then I chose a random number as an index into the array, retrieved the sound name and played it by name. It worked for me.

    With iGamersBox answer, you can just use int(random(1, 7)). If you have many sounds, you can't have them all in a choose expression.

  • [quote:xm1v7cti]If you have many sounds, you can't have them all in a choose expression.

    Yes you can. Choose can have unlimited parameters.

    From the manual

    [quote:xm1v7cti]choose(a, b [, c...])

    Choose one of the given parameters at random. E.g. choose(1, 3, 9, 20) randomly picks one of the four numbers and returns that. This also works with strings, e.g. choose("Hello", "Hi") returns either Hello or Hi. Any number of parameters can be used as long as there are at least two.

    Choose is a nice, easy and powerful expression.

  • I'm posting in the forum as resolved, but is this question:

    Why can just click the button 7 times? Should not generate a random sound whenever I clicked? (Unfortunately, it can only be generated 7 times)

    Att

  • I'm posting in the forum as resolved, but is this question:

    Why can just click the button 7 times? Should not generate a random sound whenever I clicked? (Unfortunately, it can only be generated 7 times)

    Att

  • [quote:1jhm7rq7]If you have many sounds, you can't have them all in a choose expression.

    Yes you can. Choose can have unlimited parameters.

    Sorry I meant from a practical point of view not a technical one.

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