Error Function is not Defined (But it is)

Hello. I started working with RPG Maker MV recently and I began working on creating a plug-in and I encountered a strange error that I don't know how to resolve.


The issue is that I created a function to check the noteboxes for a notetag that is supposed to be able to be called by any class. The function definition is:


checkNotes = function(notes, tag, args, i, g, m) {
if (args == null) {
var regexp = "<" + String(tag) + ">";
} else if (args == "num") {
var regexp = "<" + String(tag) + ": (\d+)>";
} else if (args == "plusMinus") {
var regexp = "<" + String(tag) + ": (+|-)(\d+)>";
} else if (args == "num%") {
var regexp = "<" + String(tag) + ": (\d+)%>";
} else if (args == "plusMinus%") {
var regexp = "<" + String(tag) + ": (+|-)(\d+)%>";
} else if (args == "string") {
var regexp = "<" + String(tag) + ": (.+)>";
} else if (args == "statNum") {
var regexp = "<" + String(tag) + "(\w+): (\d+)>";
} else if (args == "statPlusMinus") {
var regexp = "<" + String(tag) + "(\w+): (+|-)(\d+)>";
} else if (args == "statNum%") {
var regexp = "<" + String(tag) + "(\w+): (\d+)%>";
} else if (args == "statPlusMinus%") {
var regexp = "<" + String(tag) + "(\w+): (+|-)(\d+)%>";
} else if (args == "numArray") {
var regexp = "<" + String(tag) + ": (\d{1})>";
} else
var regexp = "<" + String(tag) + String(args) + ">";
};
if (i) {
regexp += "i";
};
if (m) {
regexp += "m";
};
if (g) {
regexp += "g";
};
var vals = notes.match(RegExp(regexp));
return vals
};


Then later I go to use that function in the following function:


Game_Enemy.prototype.level = function() {
//return 1
checkNotes(this.enemy.note, "level", "num", true);
return Number($1);
};


But when the function is called upon, I get an error saying:

Code:
ReferenceError: checkNotes is not defined
    at Game_Enemy.level (NCE_BasicModule.js:133)
    at Game_Enemy.name (NCE_BasicModule.js:138)
    at Window_BattleEnemy.drawItem (rpg_windows.js:5626)
    at Window_BattleEnemy.Window_Selectable.drawAllItems (rpg_windows.js:1250)
    at Window_BattleEnemy.Window_Selectable.refresh (rpg_windows.js:1277)
    at Window_BattleEnemy.refresh (rpg_windows.js:5644)
    at Window_BattleEnemy.initialize (rpg_windows.js:5591)
    at new Window_BattleEnemy (rpg_windows.js:5580)
    at Scene_Battle.createEnemyWindow (rpg_scenes.js:2223)
    at Scene_Battle.createAllWindows (rpg_scenes.js:2156)

This is despite the fact that I had already defined the method above in the same plug-in. What did I do wrong? Everything seems in order.
What scope is checkNotes defined in, though? Is it a global function? Is it inside another function? Where did you put it in your source files?
Hmmm...Is there a reason your checknotes function has 6 parameters, but when you call it you have only 4 parameters? In all languages I work in that would crash the program as undefined function as it will be looking for a version with 4 parameters, which doesn't exist.
Hmmm...Is there a reason your checknotes function has 6 parameters, but when you call it you have only 4 parameters? In all languages I work in that would crash the program as undefined function as it will be looking for a version with 4 parameters, which doesn't exist.



Javascript allows it, the variables are set to the special value "undefined", which is techncially valid. It indicates a lack of value. It is syntactically separate from null, though if I remember correctly, null == undefined is true (though null === undefined would be false. Javascript is weird). 
What scope is checkNotes defined in, though? Is it a global function? Is it inside another function? Where did you put it in your source files?





 

The function is above Game_Enemy.level in the plugin. I don't know about the scope, though. What would it be the way I have it in the code? (On its own, not inside another function).


Edit: I got it. There was an issue with another method not being properly terminated. It works now.
The function is above Game_Enemy.level in the plugin. I don't know about the scope, though. What would it be the way I have it in the code? (On its own, not inside another function).


Edit: I got it. There was an issue with another method not being properly terminated. It works now.



Ahh yeah, that would probably have made checkNotes defined at the function scope, so it became a local variable that died after that function was over.

Original thread: https://forums.rpgmakerweb.com/threads/error-function-is-not-defined-but-it-is.63913/