Music sometimes does not play

0 favourites
  • 6 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • I have a function that call's a random music, when the music is over the function is called again to recall another random music, also I have another event that calls the main menu music. The problem is 90% of the times the music plays and everything is fine, but sometimes the music just don't want to play, I've tried lots of others ways to implement it and its still not working. Here are the events I am using.

    Any one has an idea why is this happening, the logic in the event should make sure the music to play 100% of the time, but it just not work, and its making me confused.

  • imhotep22 I can't see anything obvious, but there a couple of avenues that might be worth be pursuing:

    1) The "every 2 seconds" - I don't think this triggers immediately but only after 2 seconds have passed i.e. it won't trigger on 0 seconds. That may of course be your intention. I'm guessing you're using two second loops? If so, have you considered using the 'on "(tag)" ended' condition? I also have a hunch that the order of the every X seconds in the event might cause issues: does "on X seconds | Var = Y" always do the same as "Var = Y | on X seconds"?

    2) Is the audio sample that doesn't play random, or is it always the same one(s)? If the latter is the case, have you checked that all the audio samples work and, if you're relying upon them being the same length, that they are so? I've had situations where I've been checking a sound after a given duration presuming that it's exactly X seconds when it's been a fraction over, throwing everything out of sync. Btw, using round(1,8) means that the values 1 and 8 will be chosen half as often as the other values; floor(1,9) would give you an even distribution.

    Edit:

    I'd be inclined to ditch the function "On Play_background_music" and go for:

    Audio: On Ended "Background_music, bgMusic=0, Current_layout > 0, Music_is_muted = 0 | Audio "music_" & floor(random(1,9) not looping (tag "Background_music")

    ...and then toggle bgMusic when you stop the background music to prevent it looping.

    Edit 2:

    Of course you'd need to trigger the background music to start from somewhere for that to work

  • I just tried using "on ended" and I called the music on start of layout and the same thing happens, it plays like 5-6 times in a row, and then once it does not.

    I even called a single audio file in the function and the same thing keeps happening, the every 2 second thing was just for a testing to see if it makes any difference but it does not. I am starting to thing this is some sort of bug, because the logic used should guarantee that it would work 100% time, but it simple does not.

    So I'm just stuck here, I Guess I will have to publish my game with that little bug, because I'm just out of ideas on how to fix it. If you anything else to suggest I am all open.

  • Hmm...

    I set up a test demo but couldn't replicate the bug.

    A couple of other thoughts:

    1) Are all the sounds preloaded?

    2) Have you tried spitting out some debug text to check whether (i) the event isn't triggering, (ii) the audio action isn't triggering, or (iii) the audio event is triggering but no audio is playing? You could do this by including an action in the event playing the audio that adds the current time to a text object. If there are gaps in time sequence then it must be the case that the event isn't triggering, but if the time is always added then you know that the event triggers ok, so it must be an issue with either case (ii) or (iii), in which case you can run the game in debug, select the audio object and watch it - if the object registers as playing when you get the bug then (iii) is the cause, otherwise it's (ii).

    Apart from that I'm stuck too, sorry I couldn't be of more help :S

  • I did what you said, and in the debug all the events triggered and the sound was showing that is playing, but I was getting no sound. Then I started to preload the sound before I play, and now it seems to work fine.

    Thanks for the help, if you want a sneak peak of the game I hosted it on my server for testing here is the link

    http://mythicalnew.byethost7.com

    Edit: The page loads slower now, because of the preload, but if its the only way to fix, I can live with that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm glad that the preloading worked for you - if it takes too long to load you can break up the preloading of sounds into groups using the preload action at the start of the different layouts rather than preloading them all at the very beginning.

    Thanks for sharing the link, the game is looking good - nice work!

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