Hundreds of features to explore
Games made in Construct
Your questions answered
Popular & trusted by schools and Universities world-wide
Construct 3 runs in the browser & works offline
Students do not need accounts with us
Our educational partners
Free education resources to use in the classroom
World class complete documentation
Official and community submitted guides
Learn and share with other game developers
Upload and play games from the Construct community
Game development stories & opinions
I got about 3/4 of the way through the 'Generating Random Numbers' Tutorial before I gave up.
Is there a simple way of selecting a random music file to play at the start of each level?
I have 6 merry tracks.
Create a variable MUSICPLAY
On start of layout set MUSICPLAY to random(6)
You can use sub events off start of layout or a function to do the comparison:
If MUSICPLAY = 1, Play this music
IF MUSICPLAY = 2, play this music
This is how it looks now:
<img src="http://4.bp.blogspot.com/-GMOGZNlQq84/Ucr2K_HZ9wI/AAAAAAAAABI/lJx7FQpkwL4/s1600/fffdddd.png" border="0" />
But it's still not quite right. No music is playing. Can you see what I've done wrong?
(I set Music_Play as a global variable because I couldn't find the local variable button.)
Random gives you a float, not an integer. You need to use "floor(random(6))" and it will work.
In your particular case though, I would suggest you play sound from string, not from file, letting you construct the name of the music, something like Play "fid_"&MusicPlay, as all your music (except the first index) has a name of this type.
Floor(random(6)) did the trick!
Thanks for the tip.
You can make this a little easier if you name all the music similarly. For example, if you name the music:
You could play one of them randomly by using the "Play(By Name)" action:
Of course, naming music similarly isn't always a viable the best option.
Sorry, forgot to mention the float thing. Glad you got it working.
Develop games in your browser. Powerful, performant & highly capable.
best(easy) way is play by name
so you can leave names as is, and choose will pick random one