Variable as skill cost.

Hi everyone!
Im new to this thing, so I need some help. The base idea is to have some skills increase a variable than once its high enough other skills become usable that would use the variable as the cost. - Somewhat like TP
I have Visustella core plugins. So far I was able to define the variable maximum and how to increase it, the bar in the ui also works as intended, the skill that TEMPORARY unlocks itself is also ready.
The problem: Once the bar is full the variable is still increasing and the unlocked skill does not use the up any of it. It needs 4 points to unlock, this part is ok, and it should spend all that you have, it does not.
Thanks for the help, guys!
I assume you're using JS Skill Visible or Enable to unlock the skill.

Skills (and games/code in general) don't do anything you don't tell them to. So if you haven't configured your thing to work with the built-in cost system, you need to tell the game to deplete it.

So possible solutions are:
1 - Change your cost from a variable to an item. You could make it a Hidden Item so the player doesn't see it in the party inventory, but then it would work with the plugin parameters and you could use the Type Cost notetags to do all of this automatically.

2 - Add code to decrease the variable when you use the skill. Looking at VisuStella's Battle Core, you could put:
Code:
<JS Post-Damage>
$gameVariables._data[X]-=Y;
</JS Post-Damage>

where X is the ID of the variable and Y is the cost.
I assume you're using JS Skill Visible or Enable to unlock the skill.

Skills (and games/code in general) don't do anything you don't tell them to. So if you haven't configured your thing to work with the built-in cost system, you need to tell the game to deplete it.

So possible solutions are:
1 - Change your cost from a variable to an item. You could make it a Hidden Item so the player doesn't see it in the party inventory, but then it would work with the plugin parameters and you could use the Type Cost notetags to do all of this automatically.

2 - Add code to decrease the variable when you use the skill. Looking at VisuStella's Battle Core, you could put:
Code:
<JS Post-Damage>
$gameVariables._data[X]-=Y;
</JS Post-Damage>

where X is the ID of the variable and Y is the cost.
OMG, Thank you!
It finaly works as intended. If I can bother you with just one last thing, how can I prevent the base skills from increasing the resource variable above a specific number? I want to have a maximum of points at a time at the start, than increase it with miles stone progression later, but right now there isnt a cap.
I solved it. If anyone plans to do something like this here is how to do it.
#1 Create 2 variables; one that is the maximum "charges" you can reach and one which is the current one
#2 Create 2 skills; one that deals damage and another that drains youre mp and calls a common event
#3 Create a common event that calls the damageing skill and adds to the current value x with an if statement which resets current value to maximum value if current would be higher than max
#4 Create a 3rd skill with damage formula 'base formula * v[2]' and add to the note box:

Skill Require Enable>

<JS Skill Enable>

enabled = $gameVariables.value(2) >= 4;

</JS Skill Enable>

<JS Pre-End Action>

$gameVariables._data[2]=0

</JS Pre-End Action>

#5 If you want to have bar showing the charges use the skillstatescore pugin; create a new resource type for maximum add the 1st variable abd for current the 2nd one


Im sure there are more effective ways to do this if you know how to code, but I dont
#1 Create 2 variables; one that is the maximum "charges" you can reach and one which is the current one
#3 Create a common event that calls the damageing skill and adds to the current value x with an if statement which resets current value to maximum value if current would be higher than max
I don't understand why you need two variables here. In your common event, just say:
Conditional Branch -> Variable 2 < 4
--Control Variable -> 2 -> +1

So you only increase the variable if it's under your maximum. If your maximum is always the same value, then there's no reason for it to be a variable - variables are, by definition, things that can change.

Original thread: https://forums.rpgmakerweb.com/threads/variable-as-skill-cost.150531/