MV "If" being ignored in a Yanfly Action Sequence?

Hey all,

Plugins involved:
Yanfly's Action Sequence
Action Sequence Loops by SergeofBIBEK (this is for the "while" commands)

I've got a pretty gigantic piece of code I'm working on for a skill's action sequence. I'm putting it at the bottom of this post since it's so long. Let me break down what's going on in this action sequence:

  • This is a machine gun attack that fires a total of 20 times.
  • It fires two "hits" in each "loc".
    • Each loc is a set of anims that are the same but in different horizontal positions across the screen
  • The effect is that it will spray bullets in a seemingly random pattern across the screen
  • "mov" is allowing the "loc"s to appear from right to left, or left to right
  • "SEchoice" is playing the sound independently of the anims to save on sound channels/performance (it's the sound of 10 shots in a row)
  • "dam" is randomizing how many times the enemy is hit by the spray of bullets.
  • I put in the "else wait: 20" to see if it ever happens and it doesn't
Make sense? Hope so! Anyway, this monstrosity mostly works, however there's a weird issue. For some reason it seems like it's ignoring the "if mov == 0" parts. It just plays the sequence from top to bottom meaning it will play the animations from right to left, and never from left to right. I did break the two "if move"s apart instead of making the second one an "else". It didn't work when I had it in there as an else. In fact, I doubled this up into two sets of "if/else" based on whether the first roll is a 1 or 0 but it still only played right to left one time.

Anyway, the main question here is "why is the 'if mov == 0' condition below being ignored?"

JavaScript:
<whole action>
eval: hits = 2
eval: loc = 5
eval: mov = Math.randomInt(1)
eval: odir = 0
while odir < 2
    if mov == 0
        eval: loc = 5
        eval: SEchoice = Math.randomInt(2)
        if SEchoice == 0
            SE: gun_semi_auto_rifle_shot_00_automatic_01, 80, 100, 0
        else if SEchoice == 1
            SE: gun_semi_auto_rifle_shot_00_automatic_01, 80, 95, 0
        else if SEchoice == 2
            SE: gun_semi_auto_rifle_shot_00_automatic_01, 80, 105, 0
        end           
        while loc > 0
            eval: smg = Math.randomInt(5)
            while hits > 0
                eval: hits--
                if smg == 0 && loc == 1
                    ANIMATION 259: target
                else if smg == 1 && loc == 1
                    ANIMATION 260: target
                else if smg == 2 && loc == 1
                    ANIMATION 261: target
                else if smg == 3 && loc == 1
                    ANIMATION 262: target
                else if smg == 4 && loc == 1
                    ANIMATION 263: target
                else if smg == 5 && loc == 1
                    ANIMATION 264: target   
                else if smg == 0 && loc == 2
                    ANIMATION 265: target
                else if smg == 1 && loc == 2
                    ANIMATION 266: target
                else if smg == 2 && loc == 2
                    ANIMATION 267: target
                else if smg == 3 && loc == 2
                    ANIMATION 268: target
                else if smg == 4 && loc == 2
                    ANIMATION 269: target
                else if smg == 5 && loc == 2
                    ANIMATION 270: target
                else if smg == 0 && loc == 3
                    ANIMATION 271: target
                else if smg == 1 && loc == 3
                    ANIMATION 272: target
                else if smg == 2 && loc == 3
                    ANIMATION 273: target
                else if smg == 3 && loc == 3
                    ANIMATION 274: target
                else if smg == 4 && loc == 3
                    ANIMATION 275: target
                else if smg == 5 && loc == 3
                    ANIMATION 276: target
                else if smg == 0 && loc == 4
                    ANIMATION 277: target
                else if smg == 1 && loc == 4
                    ANIMATION 278: target
                else if smg == 2 && loc == 4
                    ANIMATION 279: target
                else if smg == 3 && loc == 4
                    ANIMATION 280: target
                else if smg == 4 && loc == 4
                    ANIMATION 281: target
                else if smg == 5 && loc == 4
                    ANIMATION 282: target
                else if smg == 0 && loc == 5
                    ANIMATION 283: target
                else if smg == 1 && loc == 5
                    ANIMATION 284: target
                else if smg == 2 && loc == 5
                    ANIMATION 285: target
                else if smg == 3 && loc == 5
                    ANIMATION 286: target
                else if smg == 4 && loc == 5
                    ANIMATION 287: target
                else if smg == 5 && loc == 5
                    ANIMATION 288: target       
                end
                ANIMATION WAIT: 1
                eval: smg = Math.randomInt(5)
            end while
            eval: loc--
            eval: hits = 2
            if loc == 0
                eval: mov = 1
                eval: odir++
                ANIMATION WAIT: 5
            end
        end while
        else
            WAIT: 20
    end   
    if mov == 1
        eval: loc = 5
        eval: SEchoice = Math.randomInt(2)
        if SEchoice == 0
            SE: gun_semi_auto_rifle_shot_00_automatic_01, 80, 100, 0
        else if SEchoice == 1
            SE: gun_semi_auto_rifle_shot_00_automatic_01, 80, 95, 0
        else if SEchoice == 2
            SE: gun_semi_auto_rifle_shot_00_automatic_01, 80, 105, 0
        end       
        while loc > 0
            eval: smg = Math.randomInt(5)
            while hits > 0
                eval: hits--
                if smg == 0 && loc == 5
                    ANIMATION 259: target
                else if smg == 1 && loc == 5
                    ANIMATION 260: target
                else if smg == 2 && loc == 5
                    ANIMATION 261: target
                else if smg == 3 && loc == 5
                    ANIMATION 262: target
                else if smg == 4 && loc == 5
                    ANIMATION 263: target
                else if smg == 5 && loc == 5
                    ANIMATION 264: target   
                else if smg == 0 && loc == 4
                    ANIMATION 265: target
                else if smg == 1 && loc == 4
                    ANIMATION 266: target
                else if smg == 2 && loc == 4
                    ANIMATION 267: target
                else if smg == 3 && loc == 4
                    ANIMATION 268: target
                else if smg == 4 && loc == 4
                    ANIMATION 269: target
                else if smg == 5 && loc == 4
                    ANIMATION 270: target
                else if smg == 0 && loc == 3
                    ANIMATION 271: target
                else if smg == 1 && loc == 3
                    ANIMATION 272: target
                else if smg == 2 && loc == 3
                    ANIMATION 273: target
                else if smg == 3 && loc == 3
                    ANIMATION 274: target
                else if smg == 4 && loc == 3
                    ANIMATION 275: target
                else if smg == 5 && loc == 3
                    ANIMATION 276: target
                else if smg == 0 && loc == 2
                    ANIMATION 277: target
                else if smg == 1 && loc == 2
                    ANIMATION 278: target
                else if smg == 2 && loc == 2
                    ANIMATION 279: target
                else if smg == 3 && loc == 2
                    ANIMATION 280: target
                else if smg == 4 && loc == 2
                    ANIMATION 281: target
                else if smg == 5 && loc == 2
                    ANIMATION 282: target
                else if smg == 0 && loc == 1
                    ANIMATION 283: target
                else if smg == 1 && loc == 1
                    ANIMATION 284: target
                else if smg == 2 && loc == 1
                    ANIMATION 285: target
                else if smg == 3 && loc == 1
                    ANIMATION 286: target
                else if smg == 4 && loc == 1
                    ANIMATION 287: target
                else if smg == 5 && loc == 1
                    ANIMATION 288: target       
                end
                ANIMATION WAIT: 1
                eval: smg = Math.randomInt(5)
            end while
            eval: hits = 2
            eval: loc--
            if loc == 0
                eval: mov = 0
                eval: odir++
                ANIMATION WAIT: 5
            end
        end while
                else
            WAIT: 20
    end
end while
action effect: target
action effect: target
action effect: target
action effect: target
action effect: target
eval: dam = Math.randomInt(100)
    if dam > 10 && dam < 70
        action effect: target
    else if dam > 70 && dam < 100
        action effect: target
        action effect: target
    end
</whole action>
Are you also using Serge's extension for nested ifs? Because by default Action Sequences can't handle that. (the "if SEchoice" inside the "if mov").

I also suspect you could use some math to cut out the majority of those "else if" conditions, but that's my first thought.

I'm a little surprised that declaring variables like that with eval statements works at all, I would've thought they'd disappear as soon as the eval finished. But if you say referencing them in other ways works, I believe you.
Are you also using Serge's extension for nested ifs? Because by default Action Sequences can't handle that. (the "if SEchoice" inside the "if mov").
Ah, I suspected something like this. It just seemed weird that some if's worked and others didn't.

Now the problem I have with this plugin is that this animation drops my fps to 1, ahhh!
I also suspect you could use some math to cut out the majority of those "else if" conditions, but that's my first thought.
I've been trying to think about how to do this more efficiently. Unfortunately there's no command to x or y offset an animation with action sequence, so I have a stupid amount of separate animations. Hell, if I could make a variable that random rolls and offset each animation by that amount... that'd be great. I'm not sure how to reference 30 different animations more cleanly otherwise.
I'm a little surprised that declaring variables like that with eval statements works at all, I would've thought they'd disappear as soon as the eval finished. But if you say referencing them in other ways works, I believe you.
I think they work within the tag. Like they won't carry over from "target action" to "whole action". If they don't work then I have no idea why 99% of my animation works as expected, lol
I'd suggest using the script call for the animation instead; it won't reduce the number of animations you need in the database, but it will make your action sequence more readable.

Code:
eval: BattleManager._logWindow.showNormalAnimation(target, 253 + 6 * loc + smg, false)

(credit to @werzaque for doing the math for me 😉 )
@ATT_Turan Wow, that looks super slick! The command doesn't seem to work, though. I even replaced the equation with a regular number:

1723172894972.png


Is it a problem that the attack hits all enemies, maybe?

EDIT: I got it to work with a different command...

JavaScript:
                eval: fin = 253 + 6 * loc + smg
                eval: $gameTroop.members()[0].startAnimation(fin, false, 0)

Storing the the equation as a variable might not have been necessary. I was fiddling around when trying to get it to work and left it in, lol. So now it looks like this:

JavaScript:
eval: mov = Math.randomInt(1)
eval: odir = 0
while odir < 2
    if mov == 0
        SE: gun_semi_auto_rifle_shot_00_automatic_01, 80, 100, 0
        eval: loc = 5       
        while loc > 0
            eval: smg = Math.randomInt(5)
            while hits > 0
                eval: hits--
                eval: fin = 253 + 6 * loc + smg
                eval: $gameTroop.members()[0].startAnimation(fin, false, 0)
                end
                WAIT: 1
                eval: smg = Math.randomInt(5)
            end while
            eval: loc--
            eval: hits = 2
            if loc == 0
                eval: mov = 1
                eval: odir++
                ANIMATION WAIT: 1
            end
        end while   
    else if mov == 1
        eval: loc = 1
        SE: gun_semi_auto_rifle_shot_00_automatic_01, 80, 100, 0
        while loc < 6
            eval: smg = Math.randomInt(5)
            while hits > 0
                eval: hits--
                eval: fin = 253 + 6 * loc + smg
                eval: $gameTroop.members()[0].startAnimation(fin, false, 0)
                end
                WAIT: 1
                eval: smg = Math.randomInt(5)
            end while
            eval: hits = 2
            eval: loc++
            if loc == 6
                eval: mov = 0
                eval: odir++
                ANIMATION WAIT: 1
            end
        end while
    end
end while

Note that I had to reverse the counting for "loc" in the second one to get the animations to play in reverse.

So this is cool that it's so clean, but for some reason it still won't play nice with the "if move == 0" even with the new plugin. Am I crazy!?
I suppose you could always use Action Sequence Impact and display your animations as "projectiles". With those commands you can have a start and an end offset and even make it so the animation stays on the spot, rather than following the battler around, like the dust clouds in this gif.
Beetle.gif

It's using the same animation, just with different offsets:
Code:
PROJECTILE ANIMATION 37: START user, GOAL user, START OFFSET -0 -20, GOAL OFFSET -0 -20
wait: 5
PROJECTILE ANIMATION 37: START user, GOAL user, START OFFSET -20 -0, GOAL OFFSET -20 -0
wait: 5
PROJECTILE ANIMATION 37: START user, GOAL user, START OFFSET +20 -20, GOAL OFFSET +20 -20
wait: 5
PROJECTILE ANIMATION 37: START user, GOAL user, START OFFSET -0 -20, GOAL OFFSET -0 -20
wait: 5
PROJECTILE ANIMATION 37: START user, GOAL user, START OFFSET -10 +20, GOAL OFFSET -10 +20
wait: 5
motion damage: user
PROJECTILE ANIMATION 37: START user, GOAL user, START OFFSET -0 -20, GOAL OFFSET -0 -20
wait: 5
PROJECTILE ANIMATION 37: START user, GOAL user, START OFFSET -20 -0, GOAL OFFSET -20 -0
wait: 5
PROJECTILE ANIMATION 37: START user, GOAL user, START OFFSET +20 -20, GOAL OFFSET +20 -20
wait: 5
PROJECTILE ANIMATION 37: START user, GOAL user, START OFFSET -0 -20, GOAL OFFSET -0 -20
wait: 5
PROJECTILE ANIMATION 37: START user, GOAL user, START OFFSET +30 +10, GOAL OFFSET 30 +10
wait: 20
PROJECTILE ANIMATION 34: START user, GOAL user, START OFFSET -0 -20, GOAL OFFSET -0 -20
Ah - I think what I gave you would work if you did [target] - but if you got it working as you like, no need to change.

And no, you don't need the separate variable, but again...no need to change just for that.

As far as the if...I'm not sure. It does look like mov will always start as 0 - Math.randomInt(x) generates a number from 0 to x-1, so Math.randomInt(1) can only produce 0. I'm not sure if that's what you're seeing as your bug.
I suppose you could always use Action Sequence Impact and display your animations as "projectiles".
This seems interesting. But it's a paid add on and seems like more stuff I'd have to learn to use. I'll consider it if I need projectile stuff, but since I'm in front view I think I can work around without it.
Ah - I think what I gave you would work if you did [target] - but if you got it working as you like, no need to change.
So I spoke too soon. I can't seem to get these animations to play on "all enemies". I would think "target" would work when the scope is set to all enemies? This only seems to matter for making targets flash; the damage registers 😳
As far as the if...I'm not sure. It does look like mov will always start as 0 - Math.randomInt(x) generates a number from 0 to x-1, so Math.randomInt(1) can only produce 0. I'm not sure if that's what you're seeing as your bug.
Oh, yeah I was operating under the idea that it would roll 0's. Boy, that raises a lot of stuff I have to look into.

But now I got the thing fixed! Although I have to use that nested if's plugin otherwise it crashes. The good news is that the lag is fixed if I use @ATT_Turan 's cleaner method of showing animations rather than a million if's. It does seem to feel slower? I think it's ignoring the animation speed set by Battle Core, not sure.
So I spoke too soon. I can't seem to get these animations to play on "all enemies".
Try replacing [target] in the script call with $gameTroop.aliveMembers()

Oh, yeah I was operating under the idea that it would roll 0's.
Just to clarify - Math.randomInt(1) does roll 0s, but only 0s. If you want to get a 50% chance of 0 or 1, you'd use Math.randomInt(2)
Try replacing [target] in the script call with $gameTroop.aliveMembers()
Sorry I'm not sure I understand what you're going for. The closest I get is this:
eval: target.startAnimation(fin, false, 0)
But that causes only enemy 0 to receive the target flashes from the screen animation I'm using. The BattleManager one I can't get to work at all regardless of using target or [target], unless I'm not understanding which part to replace.
Just to clarify - Math.randomInt(1) does roll 0s, but only 0s. If you want to get a 50% chance of 0 or 1, you'd use Math.randomInt(2)
I don't know why I said that, I guess I meant... "I thought it would roll 0-1" or "it will includethe number in brackets" or something. But yeah, in a lot of other stuff I made I wrote it as if 0 was a possibility, but did not think to add 1 to the number to make sure it tops out where I want. So I got a lot of stuff missing one of their possibilities, heh.
The BattleManager one I can't get to work at all regardless of using target or [target], unless I'm not understanding which part to replace.
Try
Code:
eval: BattleManager._logWindow.showNormalAnimation($gameTroop.aliveMembers(), 253 + 6 * loc + smg, false)

That's the function that the Animation command calls, so it ought to work.
That's the function that the Animation command calls, so it ought to work.
Ah ha! That's got it! Btw I got [target] to work as well (but without the target flashes). I guess I pasted something wrong or something.

Here's what the thing looks like:


Whew. Well, sorry all for all the back and forth. It's crazy how the last little bits of polish always take the most work. For posterity, here's the code in its final form (also, SergeofBIBEK's two plugins are both required for this to work):

JavaScript:
<whole action>
eval: hits = 2
eval: odir = 0
eval: vardir = Math.randomInt(2)
while odir < 2
    if vardir == 0
        SE: gun_fullautoedit, 80, 100, 0
        eval: loc = 5       
        while loc > 0
            eval: smg = Math.randomInt(6)
            while hits > 0
                eval: hits--
                eval: BattleManager._logWindow.showNormalAnimation($gameTroop.aliveMembers(), 253 + 6 * loc + smg, false)
                WAIT: 1
                eval: smg = Math.randomInt(6)
            end while
            eval: loc--
            eval: hits = 2
            if loc == 0
                eval: vardir = 1
                eval: odir++
                ANIMATION WAIT: 1
            end
        end while       
    else if vardir != 0
        eval: loc = 1
        SE: gun_fullautoedit, 80, 100, 0
        while loc < 6
            eval: smg = Math.randomInt(6)
            while hits > 0
                eval: hits--
                eval: BattleManager._logWindow.showNormalAnimation($gameTroop.aliveMembers(), 253 + 6 * loc + smg, false)
                WAIT: 1
                eval: smg = Math.randomInt(6)
            end while
            eval: hits = 2
            eval: loc++
            if loc == 6
                eval: vardir = 0
                eval: odir++
                ANIMATION WAIT: 1
            end
        end while
    end
end while
ANIMATION WAIT: 2
action effect: target
action effect: target
action effect: target
action effect: target
action effect: target
eval: dam = Math.randomInt(100)
    if dam > 10 && dam < 70
        action effect: target
    else if dam > 70 && dam < 100
        action effect: target
        action effect: target
    end
</whole action>
Glad you got it working!
I'm a little surprised that declaring variables like that with eval statements works at all, I would've thought they'd disappear as soon as the eval finished.
i thought the same thing, cause I remembered trying out in the past for some specific skills, but i used keywords. Hes not using a declaration keyword, and the plugin doesnt use strict mode, so theyre global.
I think they work within the tag. Like they won't carry over from "target action" to "whole action".
they do, the issue is that whole actions are processed before target actions. if you intend to declare it in a target action, you cant use it in a whole, but the other way works just fine. although in that case, you could declare it in a <setup action> and be able to use it in all the phases after.
since youve been using it before with no issue, im sure you dont need the warning, but just be careful about setting the value before using it. since its global, other skills (and parts of the game) can and will use the values set by other skills if they themselves dont
i thought the same thing, cause I remembered trying out in the past for some specific skills, but i used keywords. Hes not using a declaration keyword, and the plugin doesnt use strict mode, so theyre global.
I know the lack of declaration word makes them global, but I thought eval() was completely encapsulated, including making new global objects. Ya learn something new every day!

Original thread: https://forums.rpgmakerweb.com/threads/if-being-ignored-in-a-yanfly-action-sequence.170960/