Script for a switching state skill

Hey guys ! I have a question.

I'm using a skill that switches state from "Heal Mode" to "Kill Mode"
so I decided to use Yanfly's buff and States core and use those commands :

if (user.isStateAffected(108)) {
user.removeState(108)
user.addState(109)
} else {
if (user.isStateAffected(109)) {
user.removeState(109)
user.addState(108)
}
}

But I think I'm getting into a loop and the few knowledge I have in scripting stuffs does not seem to be enough. Any Idea of how I could do ? Thanks in advance.
Hello, how is this code being called? Is it in a parallel process that just loops forever?
Hey ! Sorry for the late answer. Actually, it is as soon as you launch the skill. I saw that I need to use the tag "Before Eval", I tried it, of course, but the problem is in the code, more than in the tag, I guess...
It's missing semicolons at the end of the lines ; That could be the issue. Also, I would do an else if statement instead of else, then if. So it would look more like this:

if (user.isStateAffected(108)) {
user.removeState(108);
user.addState(109);
} else if (user.isStateAffected(109)) {
user.removeState(109);
user.addState(108);
}

But the big thing is that you mentioned Buffs & States Core, but an effect that occurs when the skill is used would require Skill Core instead. If you're not using Skill Core, it won't work as intended.
Indeed, forgot to mention it. I'll try this and I'll give you my feedback.
It works after I changed the tag from <Before Eval> to <After Eval>.

Thanks for your help !

Original thread: https://forums.rpgmakerweb.com/threads/script-for-a-switching-state-skill.103357/