Problems with Yanfly's Skill Core

I'm looking to make a mechanic using Yanfly's Skill Core but I'm having problems.

When using an attack the Star variable should remain at 0 (The number that appears next to the Gold in the video is the star variable) but it remains at 3. I attach the code and a video where my problem appears

Any solution?

CODE:
<Custom Requirement>
if ($gameVariables.value(20) > 2)
{
value = true;
} else {
value = false;
}
</Custom Requirement>

<Custom Execution>
<Custom Execution>
$gameVariables.value(20) -= 3;
</Custom Execution>

<Cost Display Eval>
var variableId = 20;
var value = 3;
$gameVariables.setValue(variableId, value);
</Cost Display Eval>

<Custom Cost Display>
\c[4]\v[20]\c[0] STAR
</Custom Cost Display>

I'm looking to make a mechanic using Yanfly's Skill Core but I'm having problems.

When using an attack the Star variable should remain at 0 (The number that appears next to the Gold in the video is the star variable) but it remains at 3. I attach the code and a video where my problem appears

Any solution?

CODE:
<Custom Requirement>
if ($gameVariables.value(20) > 2)
{
value = true;
} else {
value = false;
}
</Custom Requirement>

<Custom Execution>
<Custom Execution>
$gameVariables.value(20) -= 3;
</Custom Execution>

<Cost Display Eval>
var variableId = 20;
var value = 3;
$gameVariables.setValue(variableId, value);
</Cost Display Eval>

<Custom Cost Display>
\c[4]\v[20]\c[0] STAR
</Custom Cost Display>


value() is a getter function, and returns what's in the variable. You can't do arithmetic operations on it because it isn't actually providing access to the underlying data. You need to do

$gamevariables.setValue(20, $gameVariables.value(20) - 3);
In addition to what Trihan said:

You have two <Custom Execution> tags. That may be causing errors because it's trying to read the second one as a JavaScript code statement but it isn't.

You can make some of your code a lot shorter, which may help it be easier to read and less for you to type. For example:
Code:
<Custom Requirement>
value = $gameVariables.value>20;
</Custom Requirement>

<Cost Display Eval>
$gameVariables.setValue(20, 3);
</Cost Display Eval>
value() is a getter function, and returns what's in the variable. You can't do arithmetic operations on it because it isn't actually providing access to the underlying data. You need to do

$gamevariables.setValue(20, $gameVariables.value(20) - 3);
Still not resetting the variable :C

NEW CODE:

<Custom Requirement>

if ($gameVariables.value(20) > 2)

{

value = true;

} else {

value = false;

}

</Custom Requirement



<Custom Execution>

$gameVariables.value(20) - 3;

</Custom Execution>



<Cost Display Eval>

var variableId = 20;

var value = 3;

$gamevariables.setValue(20, $gameVariables.value(20) - 3);

</Cost Display Eval>



<Custom Cost Display>

\c[4]\v[20]\c[0] STAR

</Custom Cost Display>
<Custom Execution>

$gameVariables.value(20) - 3;

</Custom Execution>
its what Trihan said earlier. that line in the custom execution tag doesnt do anything as the value function only retrieves data. replace that with
Code:
$gamevariables.setValue(20, $gameVariables.value(20) - 3);
Yeah, you replaced the wrong bit. You changed the cost display eval and not the custom execution.
<Custom Execution>
$gameVariables.value(20) - 3;
</Custom Execution>
That is still not what Trihan told you to do.
Yeah, you replaced the wrong bit. You changed the cost display eval and not the custom execution.
I fixed the code just as you told me and it still fails. I realized that when opening the tab where the attack is, 3 is added to the variable and it is not subtracted even if the attack is used.

We can't offer any additional advice without seeing what all of your notetags currently say.
We can't offer any additional advice without seeing what all of your notetags currently say.
Sorry

New code:

<Custom Requirement>

if ($gameVariables.value(20) > 2)

{

value = true;

} else {

value = false;

}

</Custom Requirement



<Custom Execution>

$gamevariables.setValue(20, $gameVariables.value(20) - 3);

</Custom Execution>



<Cost Display Eval>

var variableId = 20;

var value = 3;

$gameVariables.setValue(variableId, value);

</Cost Display Eval>



<Custom Cost Display>

\c[4]\v[20]\c[0] STAR

</Custom Cost Display>


Basically it's the same, I just changed what they told me was wrong and it still doesn't work
I don't get the point of the display eval and custom cost display. And then the interaction with the execution.

- Display Eval sets the variable to 3

- Cost Display displays the variable - why use the variable at all? Just print the number 3 for the cost.

- Execution subtracts 3 from the variable - why? Just set it to 0. Or, as said above, don't use it at all

- Your execution doesn't work because you've misspelled $gameVariables
I don't get the point of the display eval and custom cost display. And then the interaction with the execution.

- Display Eval sets the variable to 3

- Cost Display displays the variable - why use the variable at all? Just print the number 3 for the cost.

- Execution subtracts 3 from the variable - why? Just set it to 0. Or, as said above, don't use it at all

- Your execution doesn't work because you've misspelled $gameVariables
Hello.

I decided to eliminate the cost display eval, now the variable is subtracted as it should but there are a few problems.

1) The attack is still available even if the variable is less than 3

2) If the attack continues to be used, the variable will remain in negative numbers. I don't know if there is a way to control that it doesn't go below 0 and that it doesn't go over 5.

I attached the new code

<Custom Requirement>
if ($gameVariables.value(20) >= 3) {
value = true;
} else {
value = false;
}
</Custom Requirement

<Custom Execution>
$gameVariables.setValue(20, $gameVariables.value(20) - 3);
</Custom Execution>

<Custom Cost Display>
\c[4]3\c[0] STAR
</Custom Cost Display>
You just need to look at everything a little more critically. Especially when you have a huge clue as to where the problem is - your Custom Requirement isn't getting run because you're missing an angled bracket on the bottom.

The code in it isn't wrong, but it's still more convoluted than it needs to be:
Code:
<Custom Requirement>
value = $gameVariables.value(20)>=3;
</Custom Requirement>

(and even if you kept it as an if/else, you wouldn't need the braces)
You just need to look at everything a little more critically. Especially when you have a huge clue as to where the problem is - your Custom Requirement isn't getting run because you're missing an angled bracket on the bottom.

The code in it isn't wrong, but it's still more convoluted than it needs to be:
Code:
<Custom Requirement>
value = $gameVariables.value(20)>=3;
</Custom Requirement>

(and even if you kept it as an if/else, you wouldn't need the braces)
Hello

I fixed the problem by using the custom show eval so that the attack would not be shown if you do not have 3 or more points. It's not the solution I would have liked but oh well.

I have another question about the Script since I try to add a point to the variable every time I hit an enemy with more than 100% element rate, but it doesn't work. I tried to do it in the damage formulas and now I am using the Post-Damage Eval function but there is something wrong.

1697074172475.png

What works badly is the if, since I tried not to use it and if the variable is added.

I would greatly appreciate the help
What works badly is the if, since I tried not to use it and if the variable is added.

I would greatly appreciate the help
It doesnt work because its not being used right. an if conditional needs to be inside parentheses, that elementRate() by itself doesnt do anything since theres nothing calling the method, elementRate() needs to be given an element id to return a value, and when checking any of the rates, the rate is expressed as a decimal, not a direct percentage. try this:

Code:
<Post-Damage Eval>
var ele = this.getItemElements();
var eleres = 0;
ele.forEach(element => eleres += target.elementRate(element));
eleres /= ele.length;
if (eleres > 1) $gameVariables.setValue(20, $gameVariables.value(20)+1);
</Post-Damage Eval>
I fixed the problem by using the custom show eval so that the attack would not be shown if you do not have 3 or more points. It's not the solution I would have liked but oh well.
I don't understand what you're talking about here. I gave you the exact code in my last post to have your custom requirement tag work properly. Why did you change to a custom show if it's not the solution you would like?

I won't get into the errors in the post-damage since Robro helped you out there.
I don't understand what you're talking about here. I gave you the exact code in my last post to have your custom requirement tag work properly. Why did you change to a custom show if it's not the solution you would like?

I won't get into the errors in the post-damage since Robro helped you out there.
I used your code but it remained the same, I reviewed the code carefully and did not find the error. It must be something I'm not seeing because I don't know much about Javascript, but thanks for the help anyway, now I'm less lost than before
It doesnt work because its not being used right. an if conditional needs to be inside parentheses, that elementRate() by itself doesnt do anything since theres nothing calling the method, elementRate() needs to be given an element id to return a value, and when checking any of the rates, the rate is expressed as a decimal, not a direct percentage. try this:

Code:
<Post-Damage Eval>
var ele = this.getItemElements();
var eleres = 0;
ele.forEach(element => eleres += target.elementRate(element));
eleres /= ele.length;
if (eleres > 1) $gameVariables.setValue(20, $gameVariables.value(20)+1);
</Post-Damage Eval>
Thanks, it worked for me
There's literally no difference between the two tags, except one grays the skill out and one hides it entirely. Any code that works correctly in one must work correctly in the other.

Original thread: https://forums.rpgmakerweb.com/threads/problems-with-yanflys-skill-core.161720/