TypeError: Cannot read property of '6' of undefined

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.

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.
If you have 10 actors, _TSBR_SkillExp will have 10 elements, but their indexes will be 0-9.  The actors have IDs in the range of 1-10.


Where you have Number(actorID), subtract 1. OR where you're setting up _TSBR_SkillExp, use i+1 as the index instead of just i, so your array will be indexed by actor ID.  Then in the other functions you can use actorID as the index.
Thank you very much Shaz, I completely forgot I needed to do that for arrays. I decided to put -1 inside of my functions instead of a +1 inside the loop. I also adjusted the skillID by -1 because the #6 skill should have also been at slot 5. 


Unfortunately I'm still getting the same error, except with a 5 instead of a 6 now.


"TypeError: Cannot read property '5' of undefined"


Thank you again for your help, any more advice you have is greatly appreciated.
I believe user is an actor object, not an actor id, so there's no valid spot in the array for just "user". I don't know offhand, but try user.id instead of just user. 
Thanks Zalerinian, I already thought of that and tried user.id and user._id, but I get the same errors. And if that were the case, I don't understand why "user" works perfectly fine by itself in the same methods in different eval tags.
I don't really see anything obvious.  It's at this point that you need to do some debugging.


If it's saying '5' doesn't exist for undefined, that means it doesn't know what  _TSBR_SkillExp[6] is.  Set a breakpoint on that line (or maybe you can just wait until it crashes), then head to the developer console and see what's in $gameSystem and $gameSystem._TSBR_SkillExp.  Look at what it's got to work with, and you might be able to see what it doesn't like.
Hey, guys. Just wanted to give a quick update. I rewrote my code to work with actor data instead, and I got it working somehow. I think my problem was I was using "user" in Yanfly's Damage Core and Yanfly's Skill Core, but for the Skill Core you're supposed to us a and b like in the damage formula (a little unintuitive if you ask me, but it still works). Anyway, my codes perfect now, so thanks again for the help. I might release it as a plugin after 

Original thread: https://forums.rpgmakerweb.com/threads/typeerror-cannot-read-property-of-6-of-undefined.69008/