JS help with a few things

Hello folks!

The context: I'm working on a demo to build a game on top of, and have hit certain walls while trying to develop a class. Said class is supposed to be a vampire which works off of a very simple combo system as well as a stacking bleed mechanic.


Issue 1 resolved! Now I need help with the second one.

Spoiler: Issue 1
The first issue I've been having has to do with the combo system. How it's supposed to work is that the actor casts an instant skill(opener) using mana and then another non-instant skill(finisher) becomes available. The notetags I have on both skill are as follows:

Opener Skill:

JavaScript:
 <Instant Cast>
 <Skill Claw Cooldown: 1>

<Custom Execution>
$gameSwitches.setValue[1] == true;
</Custom Execution>

Finisher Skill:

JavaScript:
<Custom Show Eval>
if ($gameSwitches.value[1] == true) {
visible = true;
} else {
visible = false;
}
</Custom Show Eval>

<Custom Execution>
$gameSwitches.setValue[1] == false;
</Custom Execution>

I will admit, I'm a complete noob when it comes to JS. The codes have been put together by stitching together what I could find on the YEPSkillcore document as well as some threads I've found on the forums. I'm assuming I've made some sort of basic mistake because it doesn't work (Even after casting the opener, the finisher remains hidden).


Spoiler: Issue 2
Now, I believe the second issue will be more complicated to solve, if even possible. What I want to do is to have certain skill add a stacking debuff onto the enemy, and then certain other skills will make use of that debuff.

Using YEPBuffStatesCore, I know it is possible to make a stacking status. And I believe I can define a variable inside the status to keep track of how many stacks there are.

The issue arrives when I want to access that variable outside of the status, ie. having skills that deal different amounts of damage based on number of stacks. I've been reading up on posts even tangentially related to what I'm trying to do but so far I haven't been able to find a method to make this work and have seen some posts that make me think it may not be possible at all.

If what I want to do is not possible at all, I've come up with a secondary solution but again, I'm not positive this is possible either.

Secondary Method:

Instead of skills making use of the bleed variable that is defined within the status, they can add invisible states. Then, the bleed status itself can have a turn end effect which will check for these states, and depending on which one is active on the enemy, will execute a different effect using the bleed variable.

So ultimately, my question is that: Is there a way to do this with the first method? Is there a way to refer to a variable defined inside a status, by skills/items outside of it.

If that is not possible, would the second method work?

If anybody can help with one or either of these issues, I'd be most grateful. Thanks in advance!
Problem #1
This is the script call for switches
$gameSwitches.setValue( switchId, value);

So it would need to be $gameSwitches.setValue( 1, true);
Problem #1
This is the script call for switches
$gameSwitches.setValue( switchId, value);

So it would need to be $gameSwitches.setValue( 1, true);

I've tried writing it like that too.

Opener skill:

JavaScript:
 <Instant Cast>
 <Skill Claw Cooldown: 1>

<Custom Execution>
$gameSwitches.setValue(1, true);
</Custom Execution>

Finisher skill:

JavaScript:
<Custom Show Eval>
if ($gameSwitches.value[1]) {
visible = true;
} else {
visible = false;
}
</Custom Show Eval>

<Custom Execution>
$gameSwitches.setValue(1, false);
</Custom Execution>

It still didn't work when writing the notetags in that way.
I've tried writing it like that too.

Opener skill:

JavaScript:
 <Instant Cast>
 <Skill Claw Cooldown: 1>

<Custom Execution>
$gameSwitches.setValue(1, true);
</Custom Execution>

Finisher skill:

JavaScript:
<Custom Show Eval>
if ($gameSwitches.value[1]) {
visible = true;
} else {
visible = false;
}
</Custom Show Eval>

<Custom Execution>
$gameSwitches.setValue(1, false);
</Custom Execution>

It still didn't work when writing the notetags in that way.
I haven't checked the code personally, but you need to use $gameSwitches.value(1), not [1].
You still need to change it in your finisher skills show eval. It still has the [] not ()
Thanks a lot, that worked! I don't even know where that [] came from. I guess that's the issue with copying and splicing together code that you don't fully understand. I need to study up on basic JS as soon as get a decent chunk of time.
Cool you got it working.
Bookmark this for future reference:
MV/MZ Script Call list
Using YEPBuffStatesCore, I know it is possible to make a stacking status.
Strictly speaking, it isn't.

And I believe I can define a variable inside the status to keep track of how many stacks there are.
Correct, that you can do.

The issue arrives when I want to access that variable outside of the status
There's no difference between accessing the variable inside or outside of the state (not status).

So let's say you have some kind of Wound state that gets worse each time it's applied by an attack, you could give it:
Code:
<Custom Apply Effect>
// Takes the current value or starts it at 0
target._bleeding = target._bleeding || 0;
// Adds 1
target._bleeding++;
</Custom Apply Effect>

<Custom Remove Effect>
// Get rid of the bleeding when Wound is removed
delete target._bleeding;
</Custom Remove Effect>

You can access that _bleeding variable from anyplace you have a reference to the battler. So, in a damage formula, you could do:
Code:
let multiplier = b._bleeding || 1; (a.atk * 4 - b.def * 2) * multiplier

You may find value in reading through some basic JavaScript functions you can use in damage formulae:
@ATT_Turan

Thanks for replying! I was secretly hoping you'd see and reply to my thread as your previous comments have helped me a lot.

Strictly speaking, it isn't.

I think I've done a poor job explaining what I meant. I was referring to the turn counter when I said stack, which I realize is misleading. There are notetags the plugin gives you that allow skills and items to add or refresh the turn counter/duration of a state. What I wanted to do was to capture this number in a variable so I could use it in skills etc.

There's no difference between accessing the variable inside or outside of the state (not status).

Would you be so kind as to elaborate a little further on this? For example, if a variable defined in the database and one defined in a state/skill had the same name, would that cause an issue? Or because they are defined/called from different places, it wouldn't be an issue?

<Custom Apply Effect>
// Takes the current value or starts it at 0
target._bleeding = target._bleeding || 0;
// Adds 1
target._bleeding++;
</Custom Apply Effect>

<Custom Remove Effect>
// Get rid of the bleeding when Wound is removed
delete target._bleeding;
</Custom Remove Effect>

Thanks a lot for the code, this is a method I hadn't considered. However, I'm not sure it would be able to do what I want. I have two main points that I think may be an issue:

1) This code adds a set amount to the variable independent of what applies the state. However, I want different skills to add different amounts to this variable. I think I can still do this by only having the line that defines the variable on the state and adding the code that changes the variable to the skills and adjusting them accordingly.

2) Having the variable be equal to the number of remaining turns on a state would make it very simple to display that information to the player. Doing it the way you suggest may make the issue of displaying the number of stacks on each enemy complicated.

Thanks again for your reply, I'm still trying to figure out ways to do exactly what I want by using your code and will update the thread if I manage to solve the problem.
Would you be so kind as to elaborate a little further on this? For example, if a variable defined in the database and one defined in a state/skill had the same name, would that cause an issue?
I assume by "variable defined in the database" you're talking about the game variables - their names are actually entirely meaningless. They don't exist outside of the screen in the editor.

Aside from that, JavaScript has a thing called scope, which means things only have an effect within the area you define.

So you could put a variable called _bleeding onto your first actor, the third enemy in the current battle, any event on the map, and they all belong to those specific objects - it doesn't matter that you've given them the same name, they have their own unique value and they can be accessed from anyplace you can refer to that object.

I don't know if that helps or not.

1) This code adds a set amount to the variable independent of what applies the state. However, I want different skills to add different amounts to this variable.
You would need to take applying the state out of the Add State Effect on the skill and put it into a notetag instead.

So you might put into the state itself:
Code:
<Custom Apply Effect>
// Make sure the variable exists
target._bleeding = target._bleeding || 0;
</Custom Apply Effect>

<Custom Remove Effect>
// Get rid of the bleeding when Wound is removed
delete target._bleeding;
</Custom Remove Effect>

Then, in your skill, give it Yanfly Skill Core tags:
Code:
<After Eval>
// Replace 69 with the ID of your Wound state
target.addState(69);

// Make this be whatever amount you want this individual skill to add
target._bleeding += 5;
</After Eval>

2) Having the variable be equal to the number of remaining turns on a state would make it very simple to display that information to the player. Doing it the way you suggest may make the issue of displaying the number of stacks on each enemy complicated.
You can do it that way if you like, but Buffs & States includes functionality for displaying counters on the state.

So you could modify the above notetag:
Code:
<After Eval>
// Replace 69 with the ID of your Wound state
target.addState(69);

// Make this be whatever amount you want this individual skill to add
target._bleeding += 5;

// Set the counter
target.setStateCounter(stateId, target._bleeding);
</After Eval>

But if you just want it to be based on the state's turns, you don't need any of these notetags at all, from the very beginning. You would just reference b.stateTurns(69) in your damage formula to reference however many turns are remaining on the target (replacing 69 with the ID of the state).
@ATT_Turan
I don't know if that helps or not.

It does help tremendously! Thank you.

You would need to take applying the state out of the Add State Effect on the skill and put it into a notetag instead.

I actually got a lot of the skills I had thought of work with the code you provided in your previous post, albeit not fully. Using the Add State Effect function, the first instance of using the skill didn't change the variable at all, probably because the variable was defined in the state after the code that modifies it ran. Would I be correct in assuming that doing it through the notetags would solve that problem?

But if you just want it to be based on the state's turns, you don't need any of these notetags at all, from the very beginning. You would just reference b.stateTurns(69) in your damage formula to reference however many turns are remaining on the target (replacing 69 with the ID of the state).

I think this is exactly the solution I was looking for. Aside from the damage formula, I assume I can also reference this number(state turns) in notetags. Would that be correct?
I don't know what you're doing to tag me, but it's not working and not giving me notifications.

See how the @ is not a part of the hyperlink with the name?

If you just type @ and then the first few letters, you should get a pop-up box where you can select the name and that will make the link and send the notification.
@ATT_Turan

Sorry about that, I was copy-pasting your name.

A little update on this: I was able to get everything working %99 accurately to my original idea.

For anyone who may want to try making a similar system, or similar skills, I'll share the notetags I ended up using.

Bleed State:
JavaScript:
<Show Turns>
<Reapply Ignore Turns>

<Custom Regenerate Effect>
var bleed = (a.stateTurns(23));
user.gainHp(-bleed );
</Custom Regenerate Effect>

This makes the enemy with the bleed state take damage equal to the number of remaining turns of said state. 23 is the stateID of this Bleed State itself.

Opener Skills:
JavaScript:
 <Instant Cast>
 <Skill Claw Cooldown: 1>

 <Custom Execution>
$gameSwitches.setValue(1, true);
 </Custom Execution>


<State 23 Turns: +5>

This is one of the opener skills that allows the usage of several finishers. In my system, all the openers allow for the usage of all the finishers and therefore one switch is enough to control all of them. But through the usage of multiple switches or variables, it should be possible to have different openers allow different finishers.

Finisher Skills:
Drain:

JavaScript:
<Custom Show Eval>
if ($gameSwitches.value(1)) {
visible = true;
} else {
visible = false;
}
</Custom Show Eval>

<Custom Execution>
$gameSwitches.setValue(1, false);
</Custom Execution>

<After Eval>
user.addParam(0, b.stateTurns(23));
user.gainHp(b.stateTurns(23));
</After Eval>

This is a non-damaging ability that increases user's MaxHp and Current Hp by an amount equal to the number of remaining turns of the bleed stack on the target. Having the finisher be the ability that turns the switch off that makes finishers available will make it so that the actor will be able to use a finisher without using an opener on the next turn. If you don't want that to happen, a simple solution is to have a battle event page that turns the switch off at the end of every turn.

The other finishers I have made so far are damaging skills, and they don't have any additional notetags. The only thing to take note is that you can use

b.stateTurns(23) [23 is what I have, use your own stateID] in your damage formula to calculate damage as ATT_Turan previously mentioned.

The only issue I have not been able to solve is that I have to have the state be auto-remove by turn count for this system to work and because the lowest turn duration you can give a state is 1, the first time you apply the state, it will end up applying +1 stacks than I had intended but the subsequent applications all work correctly.

Once again, I want to thank everyone who has taken the time to help me work through these issues, especially ATT_Turan for giving me not one but multiple methods to achieve what I wanted to achieve.

Original thread: https://forums.rpgmakerweb.com/threads/js-help-with-a-few-things.167223/