MV [YR_ItemCrafting] Set Discipline Level

I'm trying to make a system that syncs YEP_SkillMasteryLevels with YR_ItemCrafting and the I realized I don't have a way to set discipline leveldirectly. Is there a way to do that?

When the player opens a given crafting menu, I want to set the discipline levelto the mastery levelof the associated skill. And then after the menu is closed, set the mastery level in sync with the discipline level. I can do the latter just fine, with the right math, but I don't have a function do accomplish the former.
wont it be equal or similar to the exp question you asked before
that is found [here]?
wont it be equal or similar to the exp question you asked before
that is found [here]?
No, it won't. That question was about syncing it the other way. The issue I've run into now is that I can't set discipline levelat all.
I'm trying to make a system that syncs YEP_SkillMasteryLevels with YR_ItemCrafting
just as a note, please link to plugins youre asking help for. Anyone who has yanfly's stuff has all the plugins available and the free stuff isnt hard to find if needs be, but googling YR_ItemCrafting didnt come up with the plugin. I had to find it through another thread asking for help that did link it.

but I don't have a function do accomplish the former.
there doesnt look like theres a particular function that sets the discipline levels. it seems that its all of it is held in $gameParty._discLevel as an array. so you'd be probing and writing values into it instead of calling a function
just as a note, please link to plugins youre asking help for. Anyone who has yanfly's stuff has all the plugins available and the free stuff isnt hard to find if needs be, but googling YR_ItemCrafting didnt come up with the plugin. I had to find it through another thread asking for help that did link it.


there doesnt look like theres a particular function that sets the discipline levels. it seems that its all of it is held in $gameParty._discLevel as an array. so you'd be probing and writing values into it instead of calling a function
What might the script call to write into that array look like?
What might the script call to write into that array look like?
you should be able to use
Code:
$gameParty._discLevel[x] = y;
to set discipline x's level to y

Im assuming the positions in the array are just the order you listed the disciplines in the plugin parameters, so x should be the position minus 1. the first is 0, the third is 2, etc.
you should be able to use
Code:
$gameParty._discLevel[x] = y;
to set discipline x's level to y

Im assuming the positions in the array are just the order you listed the disciplines in the plugin parameters, so x should be the position minus 1. the first is 0, the third is 2, etc.
I'm guessing ._discExp would set the Exp then?
yes, but the plugin has a function to increase it. if you just use the array to set the exp, it wouldnt level it up if it gained enough exp to do so.
Code:
$gameParty.increaseDiscExp(x,y)
x is the discipline and y is the amount of exp, but the x used there automatically gets 1 subtracted from it. so 1 should be the first class and do on when using the function.
you should be able to use
Code:
$gameParty._discLevel[x] = y;
to set discipline x's level to y

Im assuming the positions in the array are just the order you listed the disciplines in the plugin parameters, so x should be the position minus 1. the first is 0, the third is 2, etc.
It would seem that setting the levels and exp this way doesn't work. More troubling, I've realized that old saves don't register new disciplines, meaning if I don't manually set discipline levels and exp, the game crashes when trying to use a new discipline in a save game made prior to the discipline's implementation. I must be doing something extra stupid, because there's no way that's intended behavior.

When using an old save, the level and exp of the new discipline are both undefined, and in a new save, they return 1 and 0 respectively. What is happening?
1750435748503.png

Edit: I figured it out. Because it's an array, the third discipline is actually [2], not [3]. After changing that, I still got the same error, but the console read them both as 0 instead of undefined, so I immediately tried adding a Math.max to the level so that it would always be set to at least 1. This worked.

So in summary, to manually set the discipline levels, you use $gameParty._discLevel[x] = y, with x being the discipline(minus one because its an array) and y being the value you want to set it to. Similarly, $gameParty._discExp[x] = ywill set the discipline exp.

As a nice bonus, if anyone else runs into the issue of old saves having undefined values for new disciplines, all you would have to do is first check if the value is undefined, and set it manually if it is. I don't know how exactly one would set a conditional to check if a value is undefined, but it's probably easier to find answers for than functions of this specific plugin.
would seem that setting the levels and exp this way doesn't work. More troubling, I've realized that old saves don't register new disciplines, meaning if I don't manually set discipline levels and exp, the game crashes when trying to use a new discipline in a save game made prior to the discipline's implementation. I must be doing something extra stupid, because there's no way that's intended behavior.
thats 100% the expected behaviour. many plugins only set up particular data when a save file is created, and adding/changing said plugins after save file creation leads to problems with missing/mismatched data. its the reason why the recommendation is to always test on a new save file rather than loading one. even without plugins, theres reasons with just the base engine that require you to not load files for testing purposes as well.

When using an old save, the level and exp of the new discipline are both undefined, and in a new save, they return 1 and 0 respectively. What is happening?
you need to provide more information. mainly, when and where you are logging that and what youve done thats supposed to have changed it before logging it.

Edit:
i see your edit now.
Edit: I figured it out. Because it's an array, the third discipline is actually [2], not [3].
I mentioned that earlier when i gave you the script to check the arrays
x should be the position minus 1. the first is 0, the third is 2, etc.

As a nice bonus, if anyone else runs into the issue of old saves having undefined values for new disciplines, all you would have to do is first check if the value is undefined, and set it manually if it is. I don't know how exactly one would set a conditional to check if a value is undefined, but it's probably easier to find answers for than functions of this specific plugin.
also if you ever see in a plugin or some other js script something along the lines of
Code:
thing = thing || 0
thats exactly whats happening there. if thing has a (truthy) value, then it doesnt change. if it doesnt, then it gets set to 0

Original thread: https://forums.rpgmakerweb.com/threads/yr_itemcrafting-set-discipline-level.178388/