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,431
Reaction score
14,167
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 Profile Posts



I've been experimenting with improved memory management again, which allowed me to include items to increase player path length. These are both 44 grid spaces long, and stable. :LZSexcite:
I FINALLY DID IT! 5 years making my very first game and I just officially released it on STEAM..... OMG..... I can say I finished a game! The feelings!!!!!
Stream will be live shortly! I am going to be playing some Among Us! Feel free to drop by!
Ami
tv program always get the ratings (it's the reason why drama series has 1000+ episode),also full and nonsense of censorship (weird blur, a scene getting cut because the unconvenient viewer,but it unconvenient to me either. you never see what the original is)

i know the reason is to take cover the viewer from the negative thing,but i just laughing and mocking of them that they're always suck :guffaw:
Star Chart Idea - Just something I am working on.

Forum statistics

Threads
104,460
Messages
1,006,442
Members
135,966
Latest member
Kleik
Top