Weird Music Resuming Issue

RosalinaGalaxer

  • Posts: 153
Hey...

I'm setting my game up to pause whenever it loses focus. I'm pausing the music when the game loses focus, and resuming it when it gains focus. However, when the game gains focus, it starts the track up again - twice. When the game loses focus again, one of the tracks pauses, but the new unauthorized track continues playing. Does anybody know what's happening?

Thanks.
W̸͚̯̒͗̊̂͗̃ë̴͙̻̣̠͂́͑͘̕̚ỉ̶̱͚̤͕͍̮͛͂̇r̶̲̣̜̳͐̇͋͘d̸͈͎͓̙̔͜ ̵̠̫̜͋̄̔͘͜ǵ̷̯͍̽̍̉͐̽̈́l̶̡̛͎̬̮̮̬̠͌͊̓̇͘i̶̡̻̰̖͕̘̎͊̚t̶̬̬̤̣͌̆͌͐̔̇̀c̷̙̳̙͈̖̀̈̎̋͑̉͜͝h̴̫̀̏͜͝e̷̝͑̊̍͘s̷̥̰̙̠̺̫̆ ̷͈̯̝͘ͅe̸͍̣͇͙͕̖͗̉̓̃̓͌͝v̶͕͕̰̘̙̫͒̑e̷̞̤͍͔͐̽͌̓r̷̨̺̲͊̋͘͝͝y̸̛̱͂̚ẇ̴̨̯̤̠̱̭̣̈̍̓h̶̨̤͎̞͛͋ę̴̻̪̝̙̬̒͜r̵̗̟̼͋ĕ̴̙̬͐͌!̵̱̠̉

“I have never seen a more heated discussion about context, jazz, and cats.” - VanillaButterz

merrak

  • *
  • Posts: 2240
How have you set up your music code?

RosalinaGalaxer

  • Posts: 153
It's pretty simple, and I don't see anything that would bug it out...

Music Playing is an event in each scene (with different music of course), and Focus is part of a scene behavior attached to the scene.
W̸͚̯̒͗̊̂͗̃ë̴͙̻̣̠͂́͑͘̕̚ỉ̶̱͚̤͕͍̮͛͂̇r̶̲̣̜̳͐̇͋͘d̸͈͎͓̙̔͜ ̵̠̫̜͋̄̔͘͜ǵ̷̯͍̽̍̉͐̽̈́l̶̡̛͎̬̮̮̬̠͌͊̓̇͘i̶̡̻̰̖͕̘̎͊̚t̶̬̬̤̣͌̆͌͐̔̇̀c̷̙̳̙͈̖̀̈̎̋͑̉͜͝h̴̫̀̏͜͝e̷̝͑̊̍͘s̷̥̰̙̠̺̫̆ ̷͈̯̝͘ͅe̸͍̣͇͙͕̖͗̉̓̃̓͌͝v̶͕͕̰̘̙̫͒̑e̷̞̤͍͔͐̽͌̓r̷̨̺̲͊̋͘͝͝y̸̛̱͂̚ẇ̴̨̯̤̠̱̭̣̈̍̓h̶̨̤͎̞͛͋ę̴̻̪̝̙̬̒͜r̵̗̟̼͋ĕ̴̙̬͐͌!̵̱̠̉

“I have never seen a more heated discussion about context, jazz, and cats.” - VanillaButterz

merrak

  • *
  • Posts: 2240
Couple of ideas:

Does pausing also pause the timer managing the "do after" event? (Put a print block inside that do after wrapper to see)

Is the "when game loses / gains focus" event triggering twice? Another print block would confirm that.

RosalinaGalaxer

  • Posts: 153
Whoops, should've thought about using the print block myself.

You were right, the "gain focus" block is triggering twice. What am I supposed to do about that? I see no reason that it should trigger twice...
W̸͚̯̒͗̊̂͗̃ë̴͙̻̣̠͂́͑͘̕̚ỉ̶̱͚̤͕͍̮͛͂̇r̶̲̣̜̳͐̇͋͘d̸͈͎͓̙̔͜ ̵̠̫̜͋̄̔͘͜ǵ̷̯͍̽̍̉͐̽̈́l̶̡̛͎̬̮̮̬̠͌͊̓̇͘i̶̡̻̰̖͕̘̎͊̚t̶̬̬̤̣͌̆͌͐̔̇̀c̷̙̳̙͈̖̀̈̎̋͑̉͜͝h̴̫̀̏͜͝e̷̝͑̊̍͘s̷̥̰̙̠̺̫̆ ̷͈̯̝͘ͅe̸͍̣͇͙͕̖͗̉̓̃̓͌͝v̶͕͕̰̘̙̫͒̑e̷̞̤͍͔͐̽͌̓r̷̨̺̲͊̋͘͝͝y̸̛̱͂̚ẇ̴̨̯̤̠̱̭̣̈̍̓h̶̨̤͎̞͛͋ę̴̻̪̝̙̬̒͜r̵̗̟̼͋ĕ̴̙̬͐͌!̵̱̠̉

“I have never seen a more heated discussion about context, jazz, and cats.” - VanillaButterz

merrak

  • *
  • Posts: 2240
I'm not sure why that's happening, but you can work around it. Make an attribute "is focused" that is set to true when the game gains focus, and false when it is lost. Then in your two events, check the value of that attribute before executing your sound code. If the game gains focus and the attribute "is focused" is true, then you know it's a duplicate execution and you can skip the sound code.

rob1221

  • *
  • Posts: 9238
It's a bug that has been fixed in b9876.  For your current build just use the workaround that Merrak mentioned.

RosalinaGalaxer

  • Posts: 153
Dorp. Why didn't I think of that? It works just fine now. Thanks!

That's a very... interesting bug. I can't wait until 3.5 comes out and fixes a whole bunch of the little quirks that Stencyl has.
W̸͚̯̒͗̊̂͗̃ë̴͙̻̣̠͂́͑͘̕̚ỉ̶̱͚̤͕͍̮͛͂̇r̶̲̣̜̳͐̇͋͘d̸͈͎͓̙̔͜ ̵̠̫̜͋̄̔͘͜ǵ̷̯͍̽̍̉͐̽̈́l̶̡̛͎̬̮̮̬̠͌͊̓̇͘i̶̡̻̰̖͕̘̎͊̚t̶̬̬̤̣͌̆͌͐̔̇̀c̷̙̳̙͈̖̀̈̎̋͑̉͜͝h̴̫̀̏͜͝e̷̝͑̊̍͘s̷̥̰̙̠̺̫̆ ̷͈̯̝͘ͅe̸͍̣͇͙͕̖͗̉̓̃̓͌͝v̶͕͕̰̘̙̫͒̑e̷̞̤͍͔͐̽͌̓r̷̨̺̲͊̋͘͝͝y̸̛̱͂̚ẇ̴̨̯̤̠̱̭̣̈̍̓h̶̨̤͎̞͛͋ę̴̻̪̝̙̬̒͜r̵̗̟̼͋ĕ̴̙̬͐͌!̵̱̠̉

“I have never seen a more heated discussion about context, jazz, and cats.” - VanillaButterz