MZ {SOLVED} VisuStella Action Sequences: Conditional branches checking switches/states

Hello everyone,

im using VisuStella Battle Core and i wanted to include more damage mechanics in the common events related to every skill. Within a common event, i want to check is Switch 43 is true or not. For this i'd like to check if the target (an actor) hat a specific state (ID 39) and if yes, change Switch 43 to "on" before the damage appears.

To show you the issue, i simplified my skill and its common event: Currently it only checks whether switch 59 is active or not.

forum_question2.PNG

Above is the skill my enemy uses to attack my actor (sry for german btw)

forum_question.PNG

Above is the event called "test", which the skill "STACHEL test" is connected to.

As i said, i want the switch check to happen before the damage / skill effects take place. The switch 59 is called "Actor stunned".
In battle, when my actor is stunned (state 39), the conditional branch should lead to the box saying "switch is on", but it doesnt.

Easy to see, i dont know much about the sequences of an battle action. By sequences i refer to those steps that VisuStella Battle Core reflects with <JS Pre-Action>, <JS Post-Damage> tags etc.

It appears that my <JS Pre-Apply> notetag cannot check for the target being stunned or not, thus always keeping the switch off. I tried it with <JS Pre-Apply> and <JS Pre-Damage>, trying to find a "time window" where the state check can occur but the damage didnt got applied yet. There seems to be a problem for the engine seeing something as a "target" before damage goes through?

Again, all of this leads to the box saying "switch is off", even if my actor is stunned.

Thanks for any responses!
You did not mention in your previous post (nor, technically, in this one) that the "common event" you're trying to check this with is an action sequence.

That makes a huge difference, because when you simply put a common event as one of the Effects of a skill, it runs after the entire skill has been completed. But when you're running an event as an action sequence, it replaces the entire mechanics of the skill.

The Pre-Apply notetag happens during the Action Effect action sequence command; that's when it's determined whether the skill hits and everything associated with Game_Action.apply() runs.

So, in your example, the Pre-Apply notetag is never happening at all, because you never call Action Effect. Even if you did, there's no way to check anything inside of it.

Why don't you just put all of the stuff from the notetag into the beginning of your action sequence? Or, for that matter, just use a Conditional Branch that checks whether the target has the state and do two different things from there - do you use the switch outside of this skill?

For that matter, what are you actually doing with this? If the only thing that's different because of the state is how much damage is being done, there's no reason to be using any notetags or switches or event commands at all - just incorporate a check for having the state into the damage formula itself.
Thanks for the response, lets work things out.
You did not mention in your previous post (nor, technically, in this one) that the "common event" you're trying to check this with is an action sequence.
My bad, i thought that the <Custom Action Sequence> in the notetag would be enough to mentally connect my skill to a BattleCore.

So, in your example, the Pre-Apply notetag is never happening at all, because you never call Action Effect. Even if you did, there's no way to check anything inside of it.
Ok, i think i understood. As long as there is no "Action Effect" in the Action Sequence Common Event the <JS> notetags doesnt play a role. Do they differ from those called <JS Pre-Start Action> or <JS Post-Start Turn>? They sound more "general", like something that is not dependent from an "Action Effect" call in the event page. VisuStella wrote, they take place aimed the function BattleManager.startTurn().

Why don't you just put all of the stuff from the notetag into the beginning of your action sequence? Or, for that matter, just use a Conditional Branch that checks whether the target has the state and do two different things from there - do you use the switch outside of this skill?

Every skill should be able to access exactly this switch to check an actor for stun state / not stun state. If my game involved only one character / player-controlled actor, things would be easier. I could start a conditional branche like this:
forum_question3.PNG


But i have more than only one actor in the battle and i want to make sure the switch doesnt turn on when actor A has the "Stunned" state but the single-target attack hits actor B.

forum_question4.PNG


If you suggest to move the content from the notetag into a conditional branch, how do i check for a dynamic (changeable with every turn) "target" of the current action instead of actor A / B / C?

For that matter, what are you actually doing with this?
I... i wanna give the player a possibility to block attacks by pressing a key, receiving less damage than usual. 😢The blocking option should last a few milliseconds during the skill animation on my actor, right before the damage gets inflicted to him.
With VisuStella QTE Trigger Effects i found a neat possibility copying their approach. It doesnt require playing with ingame timers and frame-perfect inputs as i did in darker times of development.

The blocking system works fine for single-target-attacks. Problem is: The option to block is available every single time. And my logic goes: If Actor A is stunned and an enemy inflicts a damaging skill to Actor A, the player shouldnt be able to block (-> the key input does nothing). Of course, if Actor A is stunned but the enemy attacks Actor B, the block option can be used.

In order to find out, who is stunned (thus not being able to block) i wanted to check the "current target" but i didnt know an "Action Effect" was required for the <Pre-Apply>-notetag, as you pointed out. But if those <JS Pre-Apply" notetags only check after an "Action Effect", the damage is already inflicted and blocking is redundant.

I hope I have expanded the topic and my problem more. Although now it feels like the core of my question has probably come up somewhere before.
Ok, i think i understood. As long as there is no "Action Effect" in the Action Sequence Common Event the <JS> notetags doesnt play a role. Do they differ from those called <JS Pre-Start Action> or <JS Post-Start Turn>?
Yes - there is a description of all notetags in the instructions. Anything that references Game_Action.apply() will only happen when you have an Action Effect (or a regular, non-action sequence skill).

But Pre-Start Action and Pre-Start Turn don't have any target to reference.

Every skill should be able to access exactly this switch to check an actor for stun state / not stun state. If my game involved only one character / player-controlled actor, things would be easier.
I still don't understand why you need a switch. Like I said in my previous post, why can't you just do a conditional branch that asks "does the target have this state"?

In the Script field,
Code:
$target.isStateAffected(39)

I...i wanna give the player a possibility to block attacks by pressing a key, receiving less damage than usual. But if those <JS Pre-Apply" notetags only check after an "Action Effect", the damage is already inflicted and blocking is redundant.
I don't know how all of your mechanics should work, if you want the normal chance to hit and evade in addition to this blocking.

But you could make your skills Certain Hit and do this block check before you call Action Effect, knowing that will hit if you haven't successfully blocked.
I still don't understand why you need a switch. Like I said in my previous post, why can't you just do a conditional branch that asks "does the target have this state"?
You dont understand because i dont understand either. But actually i didnt know much about $target.isStateAffected(39) and its benefits. Thanks a lot! Switches are not necessary anymore... so i thought.

Ironically i have some kind of "excuse" for using switches nonetheless. So far I've only ever talked about one state (being stunned) that prevents blocking.
But im planning to implement more states that will do the same, for example a "frozen" state (basically stun with tweaks) and a "weakness" state (just not being able to block anything)

And checking for 3+ states in the conditional branch felt... wrong?

Code:
$target.isStateAffected(39) || $target.isStateAffected(44) || $target.isStateAffected(45)

Yesterday, i found about the possibility to "clumb" states together with .some and i tried it out for my action sequence common event:

Code:
let sids = [39,44,45];

If i write this in a script call textbox, it didnt connect to the following conditional branch where i wrote:
Code:
sids.some(sid=> $target.isStateAffected(sid))

I didnt question it, because it seems logical, that these two lines of code, where i define "sids" should stand together and not be seperated in a script call and a conditional branch written after.

Problem: How do i transfer the information, that my target/actor has a state that denies him blocking to the conditional branch that decides whether the key input for blocking does something or not (-> damage gets lowered or damage goes through with 100% strength)?

In the end, i came up with this:
forum_question5.PNG


Before every action effect, the target is being checked, whether he has states that deny blocking
(id 39, 44, 45). Switch 59, which felt irrelevant after your first answer, is currently necessary, because i couldnt think of something different. Is there a better way?


And maybe i will implement another switch (with ID 60), where I as developer decide, whether an enemy skill is even generally blockable. Some bosses could use attacks that the player just has to endure. Or with more difficulty options, switch 60 would help me to turn every skill not-blockable. Then, checking for three switches and many states, the conditional branch could look like this:

Code:
$gameSwitches.value(13) == true && $gameSwitches.value(59) == true && $gameSwitches.value(60) == true && $target.isStateAffected(39) || $target.isStateAffected(44) || $target.isStateAffected(45)

And im like no. Conditions, that i have to scroll to the right for in the event page, are avoidable. Currently, i prefer some block of js code that i can see in an instant.


I don't know how all of your mechanics should work, if you want the normal chance to hit and evade in addition to this blocking.
At the moment, there is actually a chance for an enemy skill being blocked but missing. It doesnt screw up the mechanics, but it looks a bit odd. On the other hand, i want my players to "train" watching an animation and deciding during which frames it seems blockable.

Since i give every enemy 2-4 own skills with animations, some kind of constant block-practice is needed. And i dont want to deny it just because the enemy wouldnt hit anyway. Train your key timing, my dear players... 😛
However, im coming to terms that the word "blocking" doesnt really fit, because physically you cant "block" something from hitting your body when it flies over your head. Well... i dont have a problem with that. Maybe it bothers me in 2-3 months.
And im like no. Conditions, that i have to scroll to the right for in the event page, are avoidable. Currently, i prefer some block of js code that i can see in an instant.
you actually dont need to explicitly check if a switch is true. "$gameSwitches.value(x)" is the same as "$gameSwitches.value(x) == true". also you can add newlines into js to make it more readable. as long as youre not cutting an expression in half or something, youre fine to add them in

just how you can use some() to condense multiple OR you can use every() for ANDs. you also dont need to reserve a line to set up the array if you know the contents of the array already, but its clearer for some to see what its doing. directly writing the array works
$gameSwitches.value(13) == true && $gameSwitches.value(59) == true && $gameSwitches.value(60) == true && $target.isStateAffected(39) || $target.isStateAffected(44) || $target.isStateAffected(45)
is the same as
Code:
[13,59,60].every(gs => $gameSwitches.value(gs)) && [39,44,45].some(state => $target.isStateAffected(state))

Before every action effect, the target is being checked, whether he has states that deny blocking
(id 39, 44, 45). Switch 59, which felt irrelevant after your first answer, is currently necessary, because i couldnt think of something different. Is there a better way?
you dont actually "need" it. if all that switch is is an indication that the target doesnt have any of the states above, you can replace it for the check you used to set its value.

you should be able to drop the script command entirely and give the conditional block the script condition:
Code:
![39,44,45].some(state => $target.isStateAffected(state)

However, im coming to terms that the word "blocking" doesnt really fit, because physically you cant "block" something from hitting your body when it flies over your head
you could try brace. you can brace for an attack, but it fails to hit you it doesnt hold an implication that you did anything to it other than prepare for it
Code:
[13,59,60].every(gs => $gameSwitches.value(gs)) && [39,44,45].some(state => $target.isStateAffected(state))
Damn, good sir. Dont mind if i use this...

The Pre-Apply notetag happens during the Action Effect action sequence command; that's when it's determined whether the skill hits and everything associated with Game_Action.apply() runs.
For that matter, what are you actually doing with this?
And thanks for freeing me from this mood with switches and <JS notetags>. I will spread the word of $target-usage to other rpg maker noobies!

You guys, thanks a lot for your input. Even though i struggled explaining what my ideas and issues were all about in the first place, you helped me with your input. Furthermore, i got new JS knowledge and im looking forward to use it to upgrade my game. Again, thanks!!
Im going to change the title of this thread, mirroring its topics in a better way. Since my problem has been fixed and have no further questions, this thread can be closed.
This thread is closed due to being marked as solved. If you need it reopened, report the thread to let us know. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/solved-visustella-action-sequences-conditional-branches-checking-switches-states.172397/