[SOLVED]How do I play random audio?

Get help using Construct 2

Post » Sat Jul 18, 2015 2:10 pm

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....
Last edited by VIKINGS on Sat Jul 18, 2015 6:36 pm, edited 1 time in total.
B
21
S
11
G
6
Posts: 414
Reputation: 5,335

Post » Sat Jul 18, 2015 2:49 pm

Using https://github.com/nutmix/RandomArray2 makes this easier.
www.blackhornettechnologies.com/Constru ... Music.capx

The framerate option is in r210, not r206.
ImageImageImage
B
71
S
22
G
259
Posts: 3,794
Reputation: 143,704

Post » Sat Jul 18, 2015 3:28 pm

Interesting code @blackhornet , but sadly your way doesn't seem to actually be random.
If I run your capx this is what I get:
Image

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...:(
B
21
S
11
G
6
Posts: 414
Reputation: 5,335

Post » Sat Jul 18, 2015 5:23 pm

ImageImageImage
B
71
S
22
G
259
Posts: 3,794
Reputation: 143,704

Post » Sat Jul 18, 2015 5:59 pm

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?
B
21
S
11
G
6
Posts: 414
Reputation: 5,335

Post » Sat Jul 18, 2015 6:06 pm

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.
ImageImageImage
B
71
S
22
G
259
Posts: 3,794
Reputation: 143,704

Post » Sat Jul 18, 2015 6:36 pm

Ok, cool thank you very much @blackhornet .
B
21
S
11
G
6
Posts: 414
Reputation: 5,335


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests