YesNoOk
avatar

How can I get something to only trigger once? (Read 4973 times)

Started by Disconcorde, September 17, 2019, 05:12:52 pm
Share this topic:
How can I get something to only trigger once?
#1  September 17, 2019, 05:12:52 pm
  • avatar
  • **
    • UK
I have a character set up so that once their life reaches 0 it'll lifeset to 300. I only want this to happen once, but no matter what I try, it happens multiple times.

I've tried:

Putting persistent = 0 on every step.
Making use of a var to try and prevent it from looping.
Putting the line of code in a different state and using a selfstate to call it.

A combination of all 3.


Yet, no matter what I do, it continues to happen repeatedly instead of only once like I want. Here's the code in its current state:


Code:
[State -2, VarSet]
type = VarSet
trigger1 = life = 0 && var(21) != 2
var(21) = 1
ignorehitpause = 1

[State -2, Resist]
type = AssertSpecial
trigger1 = life = 0 && var(21) = 1
flag = noko
flag2 = nobardisplay
ignorehitpause = 1

[State -2, ResistBy]
type = NotHitBy
trigger1 = life = 0 && var(21) = 1
value = SCA,AA,NA,SA,HA,AP,NP,SP,HP,AT,NT,ST,HT
ignorehitpause = 1

[State -2, ResistPause]
type = SuperPause
trigger1 = life = 0 && var(21) = 1
time = 5
movetime = 5
supermovetime = 5
darken = 0
unhittable = 1
ignorehitpause = 1

[State -2, ResistSet]
type = LifeSet
trigger1 = life = 0 && var(21) = 1
value = lifemax / 4.66
ignorehitpause = 1

[State -2, ResistState]
type = SelfState
trigger1 = life = 0 && var(21) = 1
value = ifelse(random < 6500, 12012, 5210)
ignorehitpause = 1

[State -2, VarSet]
type = VarSet
trigger1 = var(21) = 1
var(21) = 2
ignorehitpause = 1


Please help me.
Last Edit: September 19, 2019, 07:04:31 pm by Disconcorde
Re: How can I get something to only trigger once?
#2  September 17, 2019, 05:41:04 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
"persistent" does not work in State -1 or State -2 or State -3

However, the code you are showing looks fine to me... the triggers are logical and should achieve your goal as far as I can tell.

Although I forget how SuperPause works, maybe it is interfering with the triggers that come after?


Note that the 2nd to last controller ("ResistState") will not trigger because you are setting the Life in the controller before it, so Life will not be 0 when this is evaluated.


Are you sure that there is no other code affecting var(21), which you have not shown above?

Re: How can I get something to only trigger once?
#3  September 17, 2019, 05:44:50 pm
  • avatar
  • **
    • UK
I have checked, and this one thing. Though I have no idea what it means as I'm not the one who put it there. It's this:

Code:
[State 0, ParentVarSet]
type = ParentVarSet
triggerall = !Name = "ONI-MIKO-REIMU"
triggerall = ishelper
triggerall = parent,id = root,id
trigger1 = ishelper
var(21) = (gametime % 11 = [3, 4]) * 1 + (gametime % 11 = [6, 7]) * (root,lifemax) + (gametime % 11 = [9, 10]) * - 9999999999999
ignorehitpause = 1

The problem with that though is that there's one of these in her helper file for EVERY var and fvar, and it shouldn't be triggering anyway, because her name is "ONI-MIKO-REIMU" and that should only trigger if it isn't... var(21) doesn't appear anywhere else other than here.


EDIT:

I tried removing the above, and it did nothing. So even when var(21) isn't being used by anything else, that code still loops. There must be something fundamentally wrong with it. So if I can't use persistent, and using vars doesn't work, what can I do?!


EDIT2:

There also appears to be an issue here. I took the "life = 0" part out of this 2nd to last controller only to find that the SelfState will only go to 12012, and ignores both 6500 and 5210. I'm going to see if using ChangeState will be better but I don't think it will matter.

Code:
[State -2, ResistState]
type = SelfState
trigger1 = var(21) = 1
value = ifelse(random < 6500, 12012, 5210)
ignorehitpause = 1


EDIT3:

Nope, using ChangeState instead didn't help. ;c

So now I have two problems. First is the one I talked about in OP, and now I need to know how to get the SelfState to select randomly between States 6500, 12012 and 5210.
And I have no clue how to fix either.
Last Edit: September 17, 2019, 06:49:26 pm by Disconcorde
Re: How can I get something to only trigger once?
#4  September 17, 2019, 08:15:36 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
Try using a different Var # (instead of 21) that you are absolutely sure is not being used for anything else.  Maybe just try a few different numbers.

About the second part, "random" will generate a number of 0 - 999.  So, "random < 6500" is always true.
So just change that to random < 499.

Re: How can I get something to only trigger once?
#5  September 17, 2019, 08:37:24 pm
  • ****
    • crepa.neocities.org
ifelse(random < 333, 6500, ifelse(random < 500, 12012, 5210)) would be better.
Re: How can I get something to only trigger once?
#6  September 18, 2019, 01:29:22 am
  • avatar
  • **
    • UK
@altoiddealer
No. I'm absolutely positive that every single var goes through that parentvarset thing in the helpers. That goes for vars and fvars. And I did try deleting the parentvarset for var 21, thus making it not used anywhere else, and it still didn't work. Is there another way to make something only trigger once? I know I've seen it in another character (in YT vid, so I cannot rip code from it) before.

@DS
Thanks for your help! I'll only be able to test it if the main issue is solved first though. ;c
EDIT: I tested it independently of the rest of the code to find out that it does work, thanks DS. Do you have any suggestions for the main problem though?
Last Edit: September 18, 2019, 01:34:50 am by Disconcorde
Re: How can I get something to only trigger once?
#7  September 18, 2019, 02:18:49 am
  • ****
    • crepa.neocities.org
Reading your code I also don't see why it's not working. Probably because you're using state -2, weird things happen here. You can always use DisplayToClipboard to keep track of your vars, watch if var(21) is changing according to what you want. My other suggestion is creating a state to go whenever you reach 0 life for the first time, and continue your code from there, but I'm not sure if this will solve... you can give a try.
Re: How can I get something to only trigger once?
#8  September 18, 2019, 09:42:22 am
  • *****
  • Shame on you!
    • USA

  • Online
Set your var in 5900, and in your death state.

Resist will activate then the second one will not.
Code:
[State -2, ResistSet]
type = LifeSet
trigger1 = life = 0 && var(21) = 1
value = lifemax / 4.66
ignorehitpause = 1
 
[State -2, ResistState]
type = SelfState
trigger1 = life = 0 && var(21) = 1
value = ifelse(random < 6500, 12012, 5210)
ignorehitpause = 1
Put the lifeset in those 2 states, or under the 2nd one.
If it can happen multiple times, that means your varset never triggers, or something changes it from equaling 2. Use Debug! (Ctrl+D)
vVv Ryuko718 Updated 10/31/22 vVv
Re: How can I get something to only trigger once?
#9  September 18, 2019, 11:27:42 am
  • avatar
  • **
    • UK
@Odb718

I tried putting the lifeset under 5900,5150,5110,5100 and 5050. When I did that, the lifeset triggered after my char was already KO'd.

EDIT: I tried putting it in State 0, right before it checks for the char to be dead and send it to 5050. It's sort of working. Sometimes it doesn't at all, sometimes it does, and sometimes it does it multiple times again.

EDIT2: Nvm, it still does it multiple times, its just sometimes she's not on State 0 so she dies. I don't think the problem is with the state I put it in...
Last Edit: September 18, 2019, 11:50:15 am by Disconcorde
Re: How can I get something to only trigger once?
#10  September 19, 2019, 07:11:50 pm
  • avatar
  • **
    • UK
Okay, so I fixed the problem. I forgot that sometimes people change var values by using "v = " instead of "var() = " because of that, I thought var(21) wasn't being used, when, it infact was. So I used var(43) instead and then found a new issue.


Code:
[State -2, ResistState]
type = SelfState
trigger1 = var(43) = 2
value = ifelse(random < 333, 6500, ifelse(random < 500, 12012, 5210))
ignorehitpause = 1
This selfstate was being triggered when the var changed to 2, but it was in State -2 so it spam triggered when the var finally changed.

When I realized this I fixed it, and so this is what I ended up with, just so that anyone in future who may need this can copy:


In State -2:

Code:
[State -2, VarSet]
type = VarSet
trigger1 = life = 0 && var(43) = 0
var(43) = 1
ignorehitpause = 1

[State -2, Resist]
type = AssertSpecial
trigger1 = stateno = 14000 && var(43) < 2
flag = noko
flag2 = nobardisplay
ignorehitpause = 1

[State -2, SecondChance]
type = SelfState
trigger1 = life = 0 && var(43) < 2
value = 14000
ignorehitpause = 1

In State of your choice (I chose 14000):

Code:
[Statedef 14000]
sprpriority = -1

[State 14000, ResistBy]
type = NotHitBy
trigger1 = life = 0 && var(43) = 1
value = SCA,AA,NA,SA,HA,AP,NP,SP,HP,AT,NT,ST,HT
ignorehitpause = 1

[State 14000, ResistPause]
type = SuperPause
trigger1 = life = 0 && var(43) = 1
time = 5
movetime = 5
supermovetime = 5
darken = 0
unhittable = 1
ignorehitpause = 1

[State 14000, ResistSet]
type = LifeSet
trigger1 = life = 0 && var(43) = 1
value = lifemax / 4.66
ignorehitpause = 1

[State 14000, VarSet]
type = VarSet
trigger1 = var(43) = 1
var(43) = 2
ignorehitpause = 1

[State 14000, ResistState]
type = SelfState
trigger1 = var(43) = 2
value = ifelse(random < 333, 6500, ifelse(random < 500, 12012, 5210))
ignorehitpause = 1

And there you have it. This code should partially restore your chars HP when it reaches 0, giving it a second chance for battle. You can use it for resurrection like effects.

EDIT: Since I don't have any vfx in mind for the char, I decided to make it look like a counter attack by putting "ResistState" at the end. You don't have to do this, you could have it simply changestate to 0 or add some vfx or whatever you want!
Last Edit: September 19, 2019, 07:17:01 pm by Disconcorde
Re: How can I get something to only trigger once?
#11  September 23, 2019, 01:44:32 am
  • avatar
  • **
    • Vietnam
Okay, so I fixed the problem. I forgot that sometimes people change var values by using "v = " instead of "var() = " because of that, I thought var(21) wasn't being used, when, it infact was. So I used var(43) instead and then found a new issue.


Code:
[State -2, ResistState]
type = SelfState
trigger1 = var(43) = 2
value = ifelse(random < 333, 6500, ifelse(random < 500, 12012, 5210))
ignorehitpause = 1
This selfstate was being triggered when the var changed to 2, but it was in State -2 so it spam triggered when the var finally changed.

When I realized this I fixed it, and so this is what I ended up with, just so that anyone in future who may need this can copy:


In State -2:

Code:
[State -2, VarSet]
type = VarSet
trigger1 = life = 0 && var(43) = 0
var(43) = 1
ignorehitpause = 1

[State -2, Resist]
type = AssertSpecial
trigger1 = stateno = 14000 && var(43) < 2
flag = noko
flag2 = nobardisplay
ignorehitpause = 1

[State -2, SecondChance]
type = SelfState
trigger1 = life = 0 && var(43) < 2
value = 14000
ignorehitpause = 1

In State of your choice (I chose 14000):

Code:
[Statedef 14000]
sprpriority = -1

[State 14000, ResistBy]
type = NotHitBy
trigger1 = life = 0 && var(43) = 1
value = SCA,AA,NA,SA,HA,AP,NP,SP,HP,AT,NT,ST,HT
ignorehitpause = 1

[State 14000, ResistPause]
type = SuperPause
trigger1 = life = 0 && var(43) = 1
time = 5
movetime = 5
supermovetime = 5
darken = 0
unhittable = 1
ignorehitpause = 1

[State 14000, ResistSet]
type = LifeSet
trigger1 = life = 0 && var(43) = 1
value = lifemax / 4.66
ignorehitpause = 1

[State 14000, VarSet]
type = VarSet
trigger1 = var(43) = 1
var(43) = 2
ignorehitpause = 1

[State 14000, ResistState]
type = SelfState
trigger1 = var(43) = 2
value = ifelse(random < 333, 6500, ifelse(random < 500, 12012, 5210))
ignorehitpause = 1

And there you have it. This code should partially restore your chars HP when it reaches 0, giving it a second chance for battle. You can use it for resurrection like effects.

EDIT: Since I don't have any vfx in mind for the char, I decided to make it look like a counter attack by putting "ResistState" at the end. You don't have to do this, you could have it simply changestate to 0 or add some vfx or whatever you want!

Your char have noko flag. NoKo will bound your life to 1. So as long as NoKo flag is active. Your code won't work unless you put that noko flag to the lower priority.

And You know clearly that MUGEN code execution is asenceding order which mean (-3-->-2-->-1-->your main statedef)
------Tremble Mortal and Despair. Doom has come to this world------
Re: How can I get something to only trigger once?
#12  September 25, 2019, 03:49:04 am
  • avatar
  • **
    • UK
@Archimonde
Oh, thanks for that. I will change the "life = 0" parts to life = 1.