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

Get help using Construct 2

Post » Sun Jun 15, 2014 6:32 pm

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 8-)
Last edited by Rony Sueliton on Mon Jun 16, 2014 7:00 pm, edited 1 time in total.
B
11
S
3
G
1
Posts: 105
Reputation: 1,135

Post » Sun Jun 15, 2014 7:03 pm

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!
Every Game is a Good Game it's just few people like and few does not! Keep coding people some day you will be a "NOTCH".
B
21
S
6
G
3
Posts: 85
Reputation: 4,607

Post » Sun Jun 15, 2014 8:24 pm

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.
B
11
S
3
G
1
Posts: 105
Reputation: 1,135

Post » Sun Jun 15, 2014 8:30 pm

ImageImageImage
B
71
S
22
G
259
Posts: 3,793
Reputation: 143,702

Post » Sun Jun 15, 2014 9:38 pm

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

Can anyone help?
You do not have the required permissions to view the files attached to this post.
B
11
S
3
G
1
Posts: 105
Reputation: 1,135

Post » Mon Jun 16, 2014 5:00 am

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!
Every Game is a Good Game it's just few people like and few does not! Keep coding people some day you will be a "NOTCH".
B
21
S
6
G
3
Posts: 85
Reputation: 4,607

Post » Mon Jun 16, 2014 10:28 am

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.
B
11
S
3
G
1
Posts: 105
Reputation: 1,135

Post » Mon Jun 16, 2014 11:36 am

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.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Jun 16, 2014 12:18 pm

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

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.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Mon Jun 16, 2014 12:29 pm

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
Last edited by Rony Sueliton on Mon Jun 16, 2014 7:00 pm, edited 1 time in total.
B
11
S
3
G
1
Posts: 105
Reputation: 1,135

Next

Return to How do I....?

Who is online

Users browsing this forum: dop2000, work3 and 6 guests