Error Function is not Defined (But it is)

Crystal Noel

Veteran
Veteran
Joined
Jun 17, 2012
Messages
113
Reaction score
32
First Language
English
Primarily Uses
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.
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
934
First Language
English
Primarily Uses
N/A
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?
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,416
Reaction score
14,146
First Language
English
Primarily Uses
RMVXA
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.
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
934
First Language
English
Primarily Uses
N/A
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). 
 

Crystal Noel

Veteran
Veteran
Joined
Jun 17, 2012
Messages
113
Reaction score
32
First Language
English
Primarily Uses
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.
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
934
First Language
English
Primarily Uses
N/A
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

I think I've got my hero designs pretty much finialised ( still got some tweaks. ) In the end it'll be the four outfit colour variants with four different skintones.

I'm a bit conflicted. One the one hand, it's quite visually cool to make bodies of water that the player can interact with by going into it. However obscuring the player character from a gameplay perspective is pretty bad. Hmm... There's the option to make the area around the player visible, but then that kind of defeats the purpose of submerging them. :unsure:
Stream will be live shortly with some Darkest Dungeon! Feel free to drop by!
Another two plugins done! One being an on map grid inventory.
busy with my newborn child, can't even touch pc at all ;_;

Forum statistics

Threads
104,298
Messages
1,005,353
Members
135,812
Latest member
Yagyu_Chan
Top