[SOLVED]How do I play random audio?

0 favourites
  • 7 posts
From the Asset Store
A set of board games to make your day joyful. Play, Enjoy, Relax
  • Hello World,

    So let's say my game has 5 tracks(songs). What I want to do is when the game starts pick one of those tracks at random and start playing it at the given volume(this is set in another layout by a slider), then when that track ends I want it to pick another track randomly from the other 4 that are left(so without including the one/ones it has already played) and so on untill it plays them all at which point I want it to repeat the whole thing, pick another track from all 5, etc.

    So how would I do this? I'm guessing I have to use functions? Because if I just put the events in the menu layout(has it's own event sheet) and then a track ends while the player is in the middle of a level(different event sheet) then it wouldn't work without a call function event in every sheet?

    But I have no idea how to do the events, specially for the random part, or how to define the tracks.... I can't give each of them a unique variable like you would do a normal object, I can't put them in a family.... Could I put them in an array? And how exactly would that work?

    As you can see I am pretty confused, please help.

    Thank you.

    P.S. One more question which is not related to the above, but I figured it's not worth creating 2 topics one after the other. I just updated C2 to the latest stable version(206), wasn't it supposed to have an option to lock/cap the framerate? I can't seem to find it....

  • Using https://github.com/nutmix/RandomArray2 makes this easier.

    www.blackhornettechnologies.com/Constru ... Music.capx

    The framerate option is in r210, not r206.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Interesting code blackhornet , but sadly your way doesn't seem to actually be random.

    If I run your capx this is what I get:

    As you can see it just goes 3-1-2-0, 3-1-2-0 on and on. So maybe it randomizes it the first time, but then it just repeats that pattern, it doesn't keep randomizing it...

  • Ok, that seems to be what I am looking for blackhornet , thank you. I just have 1 more problem and a question with this capx please.

    The problem is I see 3 blank events in your capx, and from what I understand blank events run every tick. Is it possible to modify your capx to not use every tick? Is it absolutely necessary?

    Once that's resolved the question is, so I put all of those events on my main layout event sheet, and then the only event I have to include in all the other event sheets is the last one, on current ended call playnext, right?

  • You misunderstand blank-events. Those are subevents of the function, that only get called within the function. They can't run "every-tick".

    I would make a new event sheet with the sound code on it and include that in your other event sheets. Then you don't have to duplicate anything.

  • Ok, cool thank you very much blackhornet .

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