MZ Help with using a Notetag

Hi everyone, first time posting here so if I'm going about this all wrong please bear with me. Very new to this.

I am currently most of the way through designing a Combat System I want set up and have most of it functioning, but I need to make use of a JavaScript Notetag to connect the final pieces and have actually 0 knowledge of coding (never done any before at all). I'm not sure if this kind of question goes in here or a different place but I'm happy to have it moved.

The main plugins I'm using are Visustella's Battlecore, Skills & States Core, CTB Battle System & Enhanced TP systems. What I need is to use this Notetag from Skills & States Core so that the State I apply it to will remove all other states of a specific type on the battler it is attached to when it gets erased or expires (I presume I can use the same code in order to use the otherwise identical "On Expire" Notetag for that purpose).
<JS On Erase State>
code
code
</JS On Erase State>

- Used for: State Notetags
- When a state is erased, run the code added by this notetag.
- The 'user' variable refers to the current active battler.
- The 'target' variable refers to the battler affected by this state.
- The 'origin' variable refers to the one who applied this state.
- The 'state' variable refers to the current state being affected.
The "Specfic Type" would be a category I can mark using this other Skills & States Core Notetag (assuming I am correct that that's how this Notetag works):
<Category: name>
<Category: name, name, name>

- Used for: State Notetags
- Arranges states into certain/multiple categories.
- Replace 'name' with a category name to mark this state as.
- Insert multiples of this to mark the state with multiple categories.
The other thing I need is a separate iteration of the same <JS On Erase State> Notetag to toggle a switch.

That's the specifics of what I need, but I'll share more detail on exactly what I'm doing below if context is needed:
Spoiler: Extra Context
My system as I have it designed works like so: All battlers, friend & foe, have their skills divided into Martial or Magical abilities. Martial Abilities activate instantly, like standard RPG maker fair. Magical abilities however need to go through a Channeling phase before they can be used. When a Magic ability is selected, it applies the general "Channelling" state, as well as an additional "Channel - Ability X" state and toggled switch specific to the chosen ability to the Battler. While "Channeling", a unit that takes a hit has their TP increased (which I've altered with plugins to function as a "concentration" bar), and all attacks trigger a common event at their conclusion that checks to see if anyone has hit Max TP. If they do, all Channeling type states are removed from the battler and the ability switch is toggled off, since the characters 'concentration' was broken and they failed to complete the spell (this is what I need the above code to achieve).

If they do NOT reach Max TP before their next turn begins however, the Toggled On Switch will enable a second ability to be selected, which actually casts the effect part of the 'spell' in question. The switch is then toggled off and the Channeling states naturally expire at the conclusion of that turn.

Most other methods I could see of getting this kind of thing to work unfortunately seemed to require some kind of "Beginning or End of turn Check", which didn't seem possible in the CTB Battle System
.
I also have a plugin to make enemy TP bars visible so that the player can see progress towards disrupting any spell they might be channeling. I like this system because I want the player to have to make strategic tradeoffs about whether they risk casting a spell with a long channel time, since it increases the likelihood that they fail to complete the cast, but naturally the most powerful spells have the longest channel times. This is why I felt the CTB Battle System was necessary to make these tradeoffs a meaningful component of gameplay design.
Erase should cover all reasons for the state being removed, you shouldn't need to duplicate it with Erase and Expire.

I believe the code you're looking for is not provided in the VisuStella instructions, but there was a post from @Arthran earlier today that he'd figured out some of the necessary functions.

As far as the second question, do you specifically want to toggle it? That is, change it regardless of its current state? Or do you always want to turn it on or always off?

To toggle it,
Code:
<JS On Erase State>
$gameSwitches.setValue(69, !$gameSwitches.value(69));
</JS On Erase State>

That will toggle switch 69.

If you always want it to be a given value, replace all the stuff after the comma with true or false
I'm not able to test it right now, but I think that this would do it:
Code:
<JS On Erase State>
    target.statesByCategory('categoryName').forEach(state => state && target.removeState(state.id));
</JS On Erase State>

You'd want to replace categoryName with the name of the category of the states that you want to remove.
That's all working exactly as I wanted. Thanks a heap!
<JS On Erase State>
target.statesByCategory('categoryName').forEach(state => state && target.removeState(state.id)); </JS On Erase State>
Or you can just use:

<Remove Other x States>

With 'x' being the States' Category name.
Or you can just use:
that tag removes the other states on application, not removal
Oh, sorry. I must have missed that part.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-using-a-notetag.164906/