Play random sound in array

0 favourites
  • 7 posts
From the Asset Store
A set of board games to make your day joyful. Play, Enjoy, Relax
  • 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!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • oh you did use int, my bad XD

  • I just made this little app:

    <img src="" border="0" />

    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.

  • 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 :(

  • 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:

    So either the sound names are wrong or the condition that allows playing the sound files is never valid.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.

  • 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.

  • 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.

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