I made a topic yesterday requesting a script that would allow me to create a system where I could store variables in a 2D array, which would then be used be used in damage formulas and other calculations, but I got impatient and decided to try to make it myself. Unfortunately I've hit a roadblock with and error I just can't figure out how to fix.
Here's the plugin I've written that apparently works fine:
/*:
*
* @plugindesc This will make it so that every Actor
* has an individual variable for each Skill.
*
* @author Tsbrdain
*
* @help
*
* help to be added later
*
*/
var _GS_init_TSBR_SkillExp = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
_GS_init_TSBR_SkillExp.call(this);
this._TSBR_SkillExp = new Array($dataActors.length);
for (i = 0; i < $dataActors.length; i++) {
this._TSBR_SkillExp = new Array($dataSkills.length);
for (j = 0; j < $dataSkills.length; j++) {
this._TSBR_SkillExp[j] = 0;
}
}
}
Game_System.prototype.get_TSBR_SkillExp = function(actorID, skillID) {
return Number(this._TSBR_SkillExp[Number(actorID)][Number(skillID)]);
};
Game_System.prototype.set_TSBR_SkillExp = function(actorID, skillID, value) {
this._TSBR_SkillExp[Number(actorID)][Number(skillID)] = Number(value);
};
And here's the error details I get when I press F8:
TypeError: Cannot read property '6' of undefined
at Game_System.get_TSBR_SkillExp (file:///C:/Users/Nick/Documents/Games/FUN/js/plugins/TSBR_SkillExp.js:31:55)
at Game_Action.eval (eval at <anonymous> (file:///C:/Users/Nick/Documents/Games/FUN/js/plugins/YEP_SkillCore.js:1058:14), <anonymous>:1:52)
at Game_Action.applyPostDamageEval (file:///C:/Users/Nick/Documents/Games/FUN/js/plugins/YEP_SkillCore.js:1058:5)
at Game_Action.executeDamage (file:///C:/Users/Nick/Documents/Games/FUN/js/plugins/YEP_SkillCore.js:1029:10)
at Game_Action.apply (file:///C:/Users/Nick/Documents/Games/FUN/js/rpg_objects.js:1657:18)
at Game_Action.apply (file:///C:/Users/Nick/Documents/Games/FUN/js/plugins/YEP_SkillCore.js:990:36)
at Function.BattleManager.invokeNormalAction (file:///C:/Users/Nick/Documents/Games/FUN/js/rpg_managers.js:2337:18)
at Function.BattleManager.invokeAction (file:///C:/Users/Nick/Documents/Games/FUN/js/rpg_managers.js:2328:14)
at Function.BattleManager.updateAction (file:///C:/Users/Nick/Documents/Games/FUN/js/rpg_managers.js:2310:14)
at Function.BattleManager.update (file:///C:/Users/Nick/Documents/Games/FUN/js/rpg_managers.js:2048:18)
at Scene_Battle.updateBattleProcess (file:///C:/Users/Nick/Documents/Games/FUN/js/rpg_scenes.js:2054:23)
And here is the code I am using that triggers the error: (Also, the code is wrapped inside of a Yanfly Skill Core <Post-Damage Eval> tag. You can find a link to page about it here, or a direct link to the code here.) This is the only plugin I am using when the error occurs, I strongly believe there are no conflicts between the two apps, but I cannot be sure.
Based on several test I've concluded that the issue comes from the second six in that method, (I've changed the number, and it's always the second 6) the one inside the getter method, but that method works fine in other places like: (Note this code is wrapped inside of a Yanfly Damage Core <Damage Formula> tag which can be found here. I am certain it is not the cause of the error though, so it has little relevance other than proving my plugin should be working.
And for one final test I did a little bit of eventing with an autorun event at the very beginning of my project that test that both my getter and setter methods are working as intended:
And it worked perfectly. "This is True" would pop up first, and the "This is False" would continue on until I eventually closed the game.
So my final conclusion is that I'm just an idiot who just doesn't understand JavaScript and RPG Maker MV and just did something stupid. I think the error comes from the "user" (if someone could also explain what "user" is and how it works, I'd be eternally grateful. I haven't really found any information on it) inside of the getter method, (because even though it acts like the 6 is the problem, the getter method works fine in other situations.) and I really don't know how to get my script running the way I want I need it to. (Working with the Yanfly Skill Core <Post-Damage Eval> tag)
Any help is very appreciated, and thank you for reading this. If I missed anything or more details are needed, just let me know and I'll do my best to accommodate.
Here's the plugin I've written that apparently works fine:
/*:
*
* @plugindesc This will make it so that every Actor
* has an individual variable for each Skill.
*
* @author Tsbrdain
*
* @help
*
* help to be added later
*
*/
var _GS_init_TSBR_SkillExp = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
_GS_init_TSBR_SkillExp.call(this);
this._TSBR_SkillExp = new Array($dataActors.length);
for (i = 0; i < $dataActors.length; i++) {
this._TSBR_SkillExp = new Array($dataSkills.length);
for (j = 0; j < $dataSkills.length; j++) {
this._TSBR_SkillExp[j] = 0;
}
}
}
Game_System.prototype.get_TSBR_SkillExp = function(actorID, skillID) {
return Number(this._TSBR_SkillExp[Number(actorID)][Number(skillID)]);
};
Game_System.prototype.set_TSBR_SkillExp = function(actorID, skillID, value) {
this._TSBR_SkillExp[Number(actorID)][Number(skillID)] = Number(value);
};
And here's the error details I get when I press F8:
TypeError: Cannot read property '6' of undefined
at Game_System.get_TSBR_SkillExp (file:///C:/Users/Nick/Documents/Games/FUN/js/plugins/TSBR_SkillExp.js:31:55)
at Game_Action.eval (eval at <anonymous> (file:///C:/Users/Nick/Documents/Games/FUN/js/plugins/YEP_SkillCore.js:1058:14), <anonymous>:1:52)
at Game_Action.applyPostDamageEval (file:///C:/Users/Nick/Documents/Games/FUN/js/plugins/YEP_SkillCore.js:1058:5)
at Game_Action.executeDamage (file:///C:/Users/Nick/Documents/Games/FUN/js/plugins/YEP_SkillCore.js:1029:10)
at Game_Action.apply (file:///C:/Users/Nick/Documents/Games/FUN/js/rpg_objects.js:1657:18)
at Game_Action.apply (file:///C:/Users/Nick/Documents/Games/FUN/js/plugins/YEP_SkillCore.js:990:36)
at Function.BattleManager.invokeNormalAction (file:///C:/Users/Nick/Documents/Games/FUN/js/rpg_managers.js:2337:18)
at Function.BattleManager.invokeAction (file:///C:/Users/Nick/Documents/Games/FUN/js/rpg_managers.js:2328:14)
at Function.BattleManager.updateAction (file:///C:/Users/Nick/Documents/Games/FUN/js/rpg_managers.js:2310:14)
at Function.BattleManager.update (file:///C:/Users/Nick/Documents/Games/FUN/js/rpg_managers.js:2048:18)
at Scene_Battle.updateBattleProcess (file:///C:/Users/Nick/Documents/Games/FUN/js/rpg_scenes.js:2054:23)
And here is the code I am using that triggers the error: (Also, the code is wrapped inside of a Yanfly Skill Core <Post-Damage Eval> tag. You can find a link to page about it here, or a direct link to the code here.) This is the only plugin I am using when the error occurs, I strongly believe there are no conflicts between the two apps, but I cannot be sure.
Code:
<post-damage eval>
$gameSystem.set_TSBR_SkillExp(user, 6, $gameSystem.get_TSBR_SkillExp(user, 6) + 1);
</post-damage eval>
Based on several test I've concluded that the issue comes from the second six in that method, (I've changed the number, and it's always the second 6) the one inside the getter method, but that method works fine in other places like: (Note this code is wrapped inside of a Yanfly Damage Core <Damage Formula> tag which can be found here. I am certain it is not the cause of the error though, so it has little relevance other than proving my plugin should be working.
Code:
<damage formula>
eval: value = $gameSystem.get_TSBR_SkillExp(user, 6);
</damage formula>
And for one final test I did a little bit of eventing with an autorun event at the very beginning of my project that test that both my getter and setter methods are working as intended:
Code:
Script : $gameSystem.set_TSBR_SkillExp(1, 6, $gameSystem.get_TSBR_SkillExp(1, 6) + 1);
If : Script : $gameSystem.get_TSBR_SkillExp(1, 6) == 1
Text: None, Window, Bottom
This is True
: Else
Text : This is False
: End
And it worked perfectly. "This is True" would pop up first, and the "This is False" would continue on until I eventually closed the game.
So my final conclusion is that I'm just an idiot who just doesn't understand JavaScript and RPG Maker MV and just did something stupid. I think the error comes from the "user" (if someone could also explain what "user" is and how it works, I'd be eternally grateful. I haven't really found any information on it) inside of the getter method, (because even though it acts like the 6 is the problem, the getter method works fine in other situations.) and I really don't know how to get my script running the way I want I need it to. (Working with the Yanfly Skill Core <Post-Damage Eval> tag)
Any help is very appreciated, and thank you for reading this. If I missed anything or more details are needed, just let me know and I'll do my best to accommodate.