Play random sound in array

Discussion and feedback on Construct 2

Post » Sun Oct 20, 2013 9:30 pm

Hello everyone. I'm a newbie programming and using C2. I started creating a mini game for my daughters to play a board game.

Almost what I have done but there are one thing that do not work.

I want to play a random sound this way:

Array - Set value at 0 -> "Horse"
Array - Set value at 1 -> "Dog"
Array - Set value at 2 -> "Cat"
Array etc etc etc
Array etc etc etc

Set RNDSOUND to int(random(0,2))
Play Array.At.(RNDSOUND) not looping from sounds at 0db (tag"")


But don't work :(

Thank you!
B
3
Posts: 3
Reputation: 181

Post » Sun Oct 20, 2013 10:47 pm

oh you did use int, my bad XDtomsstudio2013-10-20 22:48:31
B
10
S
2
G
1
Posts: 92
Reputation: 926

Post » Mon Oct 21, 2013 12:04 am

I just made this little app:



It works just fine.

int(random(0, 2)) will give you either 0 or 1. You have to go one higher than the highest index: int(random(0, 3)) or shorter (if the range starts with zero, you can omit it) int(random(3))

The rest seems to be correct. So either the sound names are wrong or the condition that allows playing the sound files is never valid.
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Mon Oct 21, 2013 7:06 am

Sorry but i can't see your screenshot correctly..

And i can't upload nothing ( picture, code, etc) to show you all i have done, i don't haver permissions.

i have change the random like suggest but don't work :(
B
3
Posts: 3
Reputation: 181

Post » Mon Oct 21, 2013 10:45 pm

A right click on the image gives you the option to view in a larger format.

Regarding your problem there's nothing I could say to help youu further. Check if this is true: [QUOTE=tulamide]So either the sound names are wrong or the condition that allows playing the sound files is never valid.[/QUOTE] And of course, as soon as you are able to post a link, I'll be glad to help. Just "@tulamide" me then in the post.
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Tue Oct 22, 2013 9:05 pm

@tulamide ,

Thanks for your time. I have to tell you that it's very difficult for me show you something that i have because i can't post any type of url ( screenshot , code, etc)because i have not enough permissions
is there any other way to do it?

on the other hand, wanted to be more precise with what you mention to check the code.
I can tell you that I have the code exactly as you suggested, and do not hear anything. As I read in this forum, it seems, Construct has ever had problems with the sound and browsers. So I checked the sounds to see if the problem were the sounds. I created a button that reproduced the 3 sounds without using array or random and I can hear them properly in Chrome. If your code works, do not understand where can be the fault. I can not know what else to check.

Thanks again, and hope not to bother you anymore.
B
3
Posts: 3
Reputation: 181

Post » Wed Oct 23, 2013 11:39 am

I wouldn't know of any other way than having 500+ rep (you could, for example, read the manual, and many other things will raise your rep count, too).

From the description it seems, that the problem lies in the use of the array. But, I really can't help any further without seeing the capx.
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279


Return to Construct 2 General

Who is online

Users browsing this forum: worm1 and 21 guests