YesNoOk
avatar

BGM being played multiple times instead of once by PlaySnd (Read 9114 times)

Started by Disconcorde, July 30, 2019, 05:48:52 am
Share this topic:
BGM being played multiple times instead of once by PlaySnd
#1  July 30, 2019, 05:48:52 am
  • avatar
  • **
    • UK
I have added a PlaySnd to a char (HellFlamer and its not mine) but instead of playing the sound once, the sound plays multiple times at once and I have no idea why. Here's the code:

Code:
[State -2, BGM]
type = PlaySnd
triggerall = enemy,name != "ONI-MIKO-REIMU"
triggerall = enemy,name != "P-Clown"
triggerall = enemy,name != "Asgore"
triggerall = enemy,name != "Beerus"
triggerall = enemy,name != "Hakurei Reimu Dawn Apocalyptic"
trigger1 = alive && time = 1
value = S1,32
channel = 16
volume = 150
lowpriority = 1
loop = 1
ignorehitpause = 1

[State -2, StopBGM]
type = StopSnd
trigger1 = lose
value = S1,32
channel = 16
ignorehitpause = 1

[State -2, StopBGMII]
type = StopSnd
trigger1 = animelem = 5
value = S1,32
channel = 16
ignorehitpause = 1


I'm not sure why it does this. Oh, and I have checked to make sure channel 16 isn't used anywhere else. It's only used here.
Re: BGM being played multiple times instead of once by PlaySnd
#2  July 30, 2019, 07:35:25 am
  • ****
  • Still lurks regularly, but posts once a blue moon
    • Canada
Quote
trigger1 = alive && time = 1

Quote
Time

Returns the state-time of the player (that is, the number of ticks that the player has been in the current state so far).
Source: http://www.elecbyte.com/mugendocs/trigger.html#time

Since you placed that under the -2 states, what's happening is that your trigger is firing at the start of every state you enter.
Re: BGM being played multiple times instead of once by PlaySnd
#3  July 30, 2019, 09:39:00 am
  • avatar
  • **
    • UK
Where should I place it then? In state 0 or make a new one to put it in, if I make a new State just for that sound, then how do I make a changestate that only happens once?
Re: BGM being played multiple times instead of once by PlaySnd
#4  July 30, 2019, 09:42:11 am
  • avatar
  • **
    • UK
It won't even play the song if it's not in -2 though.

Tried taking && time = 1 but it still happens.
Last Edit: July 30, 2019, 09:48:48 am by Disconcorde
Re: BGM being played multiple times instead of once by PlaySnd
#5  July 30, 2019, 09:58:51 am
  • ****
  • Still lurks regularly, but posts once a blue moon
    • Canada
A method I use for playing BGM like that is through spawning a helper, and putting my PlaySnd and AssertSpecial sctrls there.

With this method, you can actually continue using state -2 to spawn the helper.  You can then use triggers to stop the helper from spawning if it already exists.  However, to minimize impact on performance, you can probably do this at state 5900 (the initialization state) instead; this way, Mugen only checks and runs the Sctrl once, instead of trying every frame.

Make sure you properly set your helper's pausemovetime / superpausetime (Or whatever they're called.) to some very large amount.  Otherwise, anytime your opponent uses a pause, the AssertSpecial will get paused too and the original BGM will play.
Just realized your demo code doesn't use AssertSpecial + NoMusic.  Well, up to you if you want to use that.

Quote
[State -2, StopBGMII]
type = StopSnd
trigger1 = animelem = 5
value = S1,32
channel = 16
ignorehitpause = 1
Looking at your code again, I do not understand what you want to do here.  Are you trying to stop the music at AnimElem 5 of your LieDead animation?  You can probably override the LieDead state and put this Sctrl there.
Re: BGM being played multiple times instead of once by PlaySnd
#6  July 30, 2019, 10:03:17 am
  • avatar
  • **
    • UK
The character is a mario and has the star sometimes, and the star theme plays during that. I checked fighter factory and that sound was S1,17 which is triggered by AnimElem 5. So I thought that using AnimElem 5 to stop the sound should stop the sound when the star theme comes up.
Re: BGM being played multiple times instead of once by PlaySnd
#7  July 30, 2019, 10:05:04 am
  • ****
    • crepa.neocities.org
Ok. First, "value" isn't a valid trigger for stopsnd, so remove them. Second, what is that "trigger1 = animelem = 5" in the stopsnd? It will make your sound stop at any anim that reaches it's element 5, I'd recomend removing this, or if you need it for something, change this to "trigger1 = anim = (number) && animelem = 5". Other than that, I tested your code and it loops normally here.

Edit: If you want to make another music play and interrupt the current/previous one, just use the same channel for both musics, no need to use the second stopsnd.
Last Edit: July 30, 2019, 10:09:16 am by DeathScythe
Re: BGM being played multiple times instead of once by PlaySnd
#8  July 31, 2019, 01:02:30 am
  • avatar
  • **
    • UK
Okay thanks.
Re: BGM being played multiple times instead of once by PlaySnd
#9  July 31, 2019, 01:11:32 am
  • avatar
  • **
    • UK
It still play multiple times at once. I tried vg's suggestion and used Statedef 5900, but it didn't play at all there.

I either put in -2 and have it play multiple times at once or in another state and have it not play at all. Why is this so hard to get right?
Re: BGM being played multiple times instead of once by PlaySnd
#10  July 31, 2019, 01:27:30 am
  • *****
  • Resident Tosspot
  • Pftheh
    • UK
    • plasmoidthunder.neocities.org
Spawn a Helper in state -2 and have the Helper handle the music; make sure to prevent the Helper from spawning if it already exists.

This is preferred because by giving the Helper a large pausemovetime/supermovetime, you can guarantee it and the nomusic AssertSpecial will persist through a (super)pause.

Oh, I want a diagram. I fucking love diagrams.
Re: BGM being played multiple times instead of once by PlaySnd
#11  July 31, 2019, 01:47:14 am
  • ******
  • I am hilarious
  • and you will quote everything I say
    • USA
Hi Disconcorde

I'm here to ask you to stop double posting. You've done it twice in this thread already

Thanks!
Re: BGM being played multiple times instead of once by PlaySnd
#12  August 01, 2019, 12:04:03 am
  • avatar
  • **
    • UK
@PlasmoidThunder

Okay, I'll try that.

@Orochi Gill

What do you mean? That fact that I replied twice instead of modifying my original comment? I wasn't aware that this was an issue. It's hardly spamming so I don't get the problem.
But I will keep it in mind for the future.



Edit:

I tried using the helper, not only does the problem still occur, but it completely glitches out the character too. I've checked to make sure the id and stateno is not being used by other helpers and its not. I think it's about time I give up on this. It's clearly not going to happen without the problem.
Last Edit: August 01, 2019, 12:12:57 am by Disconcorde
Re: BGM being played multiple times instead of once by PlaySnd
#13  August 01, 2019, 12:21:31 pm
  • *****
  • Resident Tosspot
  • Pftheh
    • UK
    • plasmoidthunder.neocities.org
Such would imply an error on your part because I've coded music into a character with that method just fine. If you want a lazy fix to your original code, add lowpriority = 1 to the PlaySnd and/or give it a channel.

Oh, I want a diagram. I fucking love diagrams.
Re: BGM being played multiple times instead of once by PlaySnd
#14  August 02, 2019, 03:32:42 am
  • avatar
  • **
    • UK
That was already in there.
Re: BGM being played multiple times instead of once by PlaySnd
#15  April 14, 2021, 08:46:49 am
  • avatar
  • **
    • UK
I got this :) Here's how it works:
Basic Elecbyte states that
1. All Intro, Win, and Lose states occur in States 170-199
2. State 5900 is for intro to a new round before
the announcer says "Fight".
3. These States occur in what as known to MUGEN code
as " RoundState = 1 " for intro, and = 4 for Win/Loss after K.O.,
respectively.

With that said, Roundstate = 2 is for the fight itself,
After fight, Before K.O., where Statedef ) starts.

If your character does not have a StateNo 0,
Please identify the Number for its helper,
like with Alpha.exe, or insert a template
Statedef 0; Then, place this code within it:


[State 0, Helper]
type = Helper
trigger1 = numhelper () = 0
name = ""
ID =
stateno =
pos = 0,0
postype = p1    ;p2,front,back,left,right
facing = 1
keyctrl = 0
ownpal = 0

"NumHelper", "ID", and "stateno" all need a number that your
character is not using in its CNS. That number needs
to go in the state below, and it needs to be pasted under the
changestate of your character's standing statedef.:


;---------------------------------------------------------------------------
; Music
[Statedef ]
type = S
physics = S
sprpriority = 0
velset = 0,0
ctrl = 1
Anim = 8502

[State 15, ±¬Å­BGM]
type = PlaySnd
trigger1 = AnimElem = 1
value = S,
volumescale = 200
channel =
loop = 1
lowpriority = 1

[State 0, DestroySelf]
type = DestroySelf
trigger1 = life = 0

;---------------------------------------------------------------------------

then you should place this in your character's -2's.:

[State -2, StopSnd]
type = StopSnd
trigger1 = Root,StateNo = 5150
channel = 13

That should stop the music when your character is desd :)