YF Skill Learn, learn requirement any skills from specific list?

Hey so im trying to figure out how I can make skills that require a specific investment.

Skill 1-9:
Code:
<Learn Show Eval>
if (user.isLearnedSkill(1)) {         // If skill 1 is learnt
value = false;                 // hide skill from tree
$gameParty.gainItem($dataItems[12], 5);     // Add hidden item to keep track of skills left to unlock Skill 10
$gameVariables.setValue(10, $gameVariables.value(10) + 1 );  // Add 1 to V10 which checks how many skills are learnt
};
</Learn Show Eval>


Skill 10:
Learn any 5 skills from 1-9 to unlock option to learn skill 10.
Code:
<Learn Require Eval>
if ($gameVariables.value(10) >= 5) {       // If V10 is greater or equal to 5
value = true;        // Can Learn
}
else {
value = false;      // Can't Learn
}
</Learn Require Eval>

<Learn Cost>
Item 12: 5 // Again to show progress on skill, would like to add back or refund consumed items, since other skills will require 10/15/...
</Learn Cost>
Problem:
Basically if I do it like this when I learn Skill 1, it endlessly overtime adds item 12 and +1 on variable.
Question:
1) Is there a way to have it only trigger when the skill is learnt? Am I using the wrong notebox and timing?
2) How would I go about setting it up for each character? I want to give the choice to spec into fire or ice or wtv and investing in will unlock a more powerful skill.
Your problem is that every time it does the eval to check to see if skill1 should be hidden, it's assuming the skill has just been learned. This eval happens every refresh of the window to see which skills should be shown. You could mitigate that by turning on a switch at the end of the item gaining and variable changing, and then wrapping the variable stuff inside an if condition that checks to see if the switch is on first, to ensure that it only runs once.

The best way to do this though is on the require eval for skill 10, just use a for loop and an array to see how many of the skills the actor already knows, like so:

JavaScript:
<Learn Require Eval>
    var listofskills = [1,2,3,4,5,6,7,8,9]
    var knownskills = []
    for (var i = 0; i < listofskills.length; i++){
        if (user.isLearnedSkill(listofskills[i])) knownskills.push(true)
    }
    if (knownskills.length >= 5){
        value = true
    } else {
        value = false
    }
</Learn Require Eval>

This checks the array of given skills, one at a time, and then pushes a 'true' to a different array if the actor knows the skill. If the array contains 5 or more 'trues' then the skill is learnable.
Your problem is that every time it does the eval to check to see if skill1 should be hidden, it's assuming the skill has just been learned. This eval happens every refresh of the window to see which skills should be shown. You could mitigate that by turning on a switch at the end of the item gaining and variable changing, and then wrapping the variable stuff inside an if condition that checks to see if the switch is on first, to ensure that it only runs once.

The best way to do this though is on the require eval for skill 10, just use a for loop and an array to see how many of the skills the actor already knows, like so:

JavaScript:
<Learn Require Eval>
    var listofskills = [1,2,3,4,5,6,7,8,9]
    var knownskills = []
    for (var i = 0; i < listofskills.lengthl i++){
        if (user.isKnownSkill(listofskills[i])) knownskills.push(true)
    }
    if (knownskills.length >= 5){
        value = true
    } else {
        value = false
    }
</Learn Require Eval>

This checks the array of given skills, one at a time, and then pushes a 'true' to a different array if the actor knows the skill. If the array contains 5 or more 'trues' then the skill is learnable.

Im not sure I understand, so
var listofskills is the skills for that tree.
var knownskills im not sure, is it just to default empty?
var i = 0; i < listofskills.lengthl i ++ // why is it lengthl and not length;? I assume this adds +1 to listofskills list "length" and I dont know what this loops does...
user.isKnownSkill checks if user has (listofskills) learnt +1?
push you mentioned it hits a true for knownskills?
knownskills.length >=5 that I get, checks for 5 or greater than conditions are met to be learn.


Either way I get this error and does not work 🙁
SyntaxError: Unexpected identifier
Sorry, I typo'd it. that for line should be for (var i = 0; i < listofskills.length; i++){ it's missing a ;, and was an l by mistake.

knownskills defaults to empty at the start of the eval. we push 'trues' to it when the for loop finds that the actor knows one of them.

the loop, when written correctly, goes from element 0 to element LENGTH of the listofskills variable we made earlier. starting in element 0 (which has the value of 1 for our example here) it then checks if user.isLearnedSkill(1) is true. If it is, it pushes a true to the empty 'knownskills' array. If the user doesn't know skill 1, it goes to the next element (which has the value 2) and tries again. When it's finished checking all the elements, it then checks how many elements the knownskills array now has. When we push a true to it, this increases it's length by 1. So, 5 trues, and your actor knows 5 of the skills.
Sorry, I typo'd it. that for line should be for (var i = 0; i < listofskills.length; i++){ it's missing a ;, and was an l by mistake.

knownskills defaults to empty at the start of the eval. we push 'trues' to it when the for loop finds that the actor knows one of them.

the loop, when written correctly, goes from element 0 to element LENGTH of the listofskills variable we made earlier. starting in element 0 (which has the value of 1 for our example here) it then checks if user.isLearnedSkill(1) is true. If it is, it pushes a true to the empty 'knownskills' array. If the user doesn't know skill 1, it goes to the next element (which has the value 2) and tries again. When it's finished checking all the elements, it then checks how many elements the knownskills array now has. When we push a true to it, this increases it's length by 1. So, 5 trues, and your actor knows 5 of the skills.

Cool that makes more sense now I understand a bit more, its hard when you dont know all the variables I forgot isLearnedskill something you can check.
BTW
TypeError: undefined is not a function
Still doesn't work which is weird, Closure Compiler checked out find but I actually tired it before messaging you assuming it was a typo.
Sorry, second typo. isKnownSkill() should be isLearnedSkill(), I had pulled that from your first post and managed to put my own made up function in there instead of it somehow. XD

The code in my original post should work now.
Sorry, second typo. isKnownSkill() should be isLearnedSkill(), I had pulled that from your first post and managed to put my own made up function in there instead of it somehow. XD

The code in my original post should work now.

Awesome Thanks! It works, I do have 2 skills one of my hero starts with and it doesn't seem to factor in the 5 skills for some reason, I think to keep the number I will just add var knownskills = [1,2], it works this way.
By any chance is there a site that lists all the possible terms you can use aka the isLearnedSkill or anything in that regard?

I feel like its a lot of work to have switches go on to give an item that basically just shows how many skills I learnt, its not perfect but if theres not an easier way then making 30 switches per skill, per actor, ill leave it.
Honestly I found these by digging around in the core files. If you open rpg_objects.js and search for 'Game_Actor.prototype' 'Game_Battler.prototype' and 'Game_BattlerBase.prototype' you can find all of the functions defined on those objects. For reference, an actor is a battler, which is also a battlerbase object, meaning any of the functions defined on any of those three 'prototypes' can be called from an actor object (in this case user).

An alternative method is to pop open the console and open an actor object in the console command window ($gameParty.leader() for a quick example), and you can then expand it to see what all you have access to from that object.

It looks like user.hasSkill(X) can be used for skills that weren't learned via level up or the skill learn system, but it probably also includes skills that were granted via equipment or states as well, which might not be ideal.

Rather than just push [1,2] to the knownskills array, why not take those two skills out of the pool, and then reduce the requirement to 3+ skills learned? If the actor always knows the first two, there's no way they couldn't know them anymore, right?

var listofskills = [3,4,5,6,7,8,9]
if (knownskills.length >= 3)

Original thread: https://forums.rpgmakerweb.com/threads/yf-skill-learn-learn-requirement-any-skills-from-specific-list.120653/