Test for buffs with Action Sequence?

My friend gave me this cool idea for an ability where if you have a buff for any stat you get a buff for every stat, and I've gotten everything down except for checking if the target has a buff. Any way to do this in Action Sequence?

EDIT: I messed around with it for another few minutes and got it, but if anyone can improve it, please let me know


<setup action>
clear battle log
display action
immortal: targets, true
perform start
wait for movement
cast animation
wait for animation
</setup action>

<whole action>
if (target._buffs[0] > 0)
change switch 4: on
end
if (target._buffs[1] > 0)
change switch 4: on
end
if (target._buffs[2] > 0)
change switch 4: on
end
if (target._buffs[3] > 0)
change switch 4: on
end
if (target._buffs[4] > 0)
change switch 4: on
end
if (target._buffs[5] > 0)
change switch 4: on
end
if (target._buffs[6] > 0)
change switch 4: on
end
if (target._buffs[7] > 0)
change switch 4: on
end

if $gameSwitches.value(4)
add atk buff: target, 4
add def buff: target, 4
add mat buff: target, 4
add mdf buff: target, 4
add agi buff: target, 4
add luk buff: target, 4
end
death break
</whole action>

<target action>
</target action>

<follow action>

</follow action>

<finish action>
immortal: targets, false
change switch 4: off
wait for new line
clear battle log
perform finish
wait for movement
wait for effect
</finish action>


if there's a better way to do this, like a for loop and a variable instead of testing each stat individually, again, please let me know!

EDIT 2: Breaking news! the move doesn't work in game??? whenever I use it, it gives me the error "Cannot read property 'toUpperCase' of undefined" and when I look at the console it shows all the action sequence packs and the YEP battle engine core have errors, what's going wrong?

EDIT 3: man I'm not good at this, turns out I put "change switch 4 = off" instead of "change switch 4: off" in the note tags for the move. the move works and it's super cool. if you can improve it tho still reply 😀

Original thread: https://forums.rpgmakerweb.com/threads/test-for-buffs-with-action-sequence.85482/