I'm a beginner coder in RPG Maker MV and having a hard time solving an undefined error. I'm trying to use drawtext to add text on a Window_Base whenever the cursor on my Window_Command moves. However, drawtext is throwing an undefined error inside my prototype function Window_SecondCommand.prototype.cursorDown
here is my whole code:
here is my whole code:
Input.keyMapper["71"] = "gambitMenu";
//global variables
var ownGlobalCommand = 0; //what command is chosen
_alias_scene_map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function()
{
_alias_scene_map_update.call(this);
if(Input.isTriggered("gambitMenu")) SceneManager.push(Scene_GambitMenu);
}
function Scene_GambitMenu() {
this.initialize.apply(this, arguments);
}
Scene_GambitMenu.prototype = Object.create(Scene_MenuBase.prototype);
Scene_GambitMenu.prototype.constructor = Scene_GambitMenu;
Scene_GambitMenu.prototype.initialize = function() {
Scene_MenuBase.prototype.initialize.call(this);
};
Scene_GambitMenu.prototype.create = function()
{
var init = $gameVariables.value(21);
if(init == 0)
{
initializeSlots();
}
Scene_MenuBase.prototype.create.call(this);
this._customWindow = new Window_GambitCustom(0, 0, 320, 240);
this._customWindow.drawText("First Box", 0, 0);
this.addWindow(this._customWindow);
this._customCommandWindow = new Window_CustomCommand(0, 250);
this._customCommandWindow.setHandler("addSlotCommand", this.addSlotCommand.bind(this));
this._customCommandWindow.setHandler("swapCommand", this.swapCommand.bind(this));
this._customCommandWindow.setHandler("clearCommand", this.clearCommand.bind(this));
this._customCommandWindow.setHandler("clearAllCommand", this.clearAllCommand.bind(this));
this.addWindow(this._customCommandWindow);
this._secondCommandWindow = new Window_SecondCommand(350, 0);
this._secondCommandWindow.setHandler("cancel", this.exitSecond.bind(this));
var numSlot = $gameVariables.value(22);
var numCommand = numSlot.length;
var stringCommand = '';
for(var i = 0; i < numCommand; i++)
{
this._secondCommandWindow.setHandler("slotCommand"+i, this.slotCommand.bind(this, i));
}
this.addWindow(this._secondCommandWindow);
this._secondCommandWindow.deactivate();
}
Scene_GambitMenu.prototype.start = function() {
Scene_MenuBase.prototype.start.call(this);
this._secondCommandWindow.refresh(); //this is important to load images first time the Scene is started along with imagemanager.reserveface('imagename');
}
Scene_GambitMenu.prototype.addSlotCommand = function () {
ownGlobalCommand = 1;
this._secondCommandWindow.refresh();
this._customWindow.contents.clear();
this._customWindow.drawText("ADD", 0, 0);
this.addWindow(this._customWindow);
this._customCommandWindow.deactivate();
this._secondCommandWindow.activate();
}
Scene_GambitMenu.prototype.swapCommand = function () {
ownGlobalCommand = 2;
this._secondCommandWindow.refresh();
this._customCommandWindow.deactivate();
this._secondCommandWindow.activate();
}
Scene_GambitMenu.prototype.clearCommand = function () {
ownGlobalCommand = 3;
this._secondCommandWindow.refresh();
this._customCommandWindow.deactivate();
this._secondCommandWindow.activate();
}
Scene_GambitMenu.prototype.clearAllCommand = function () {
ownGlobalCommand = 4;
this._secondCommandWindow.refresh();
this._customCommandWindow.deactivate();
this._secondCommandWindow.activate();
}
Scene_GambitMenu.prototype.slotCommand = function (i) {
console.log("Index: "+i);
if(ownGlobalCommand == 1)
{
this._customWindow.contents.clear();
this._customWindow.drawText("Add", 0, 0);
this.addWindow(this._customWindow);
}
if(ownGlobalCommand == 2)
{
this._customWindow.contents.clear();
this._customWindow.drawText("Swap", 0, 0);
this.addWindow(this._customWindow);
}
if(ownGlobalCommand == 3)
{
this._customWindow.contents.clear();
this._customWindow.drawText("Clear", 0, 0);
this.addWindow(this._customWindow);
}
if(ownGlobalCommand == 4)
{
this._customWindow.contents.clear();
this._customWindow.drawText("Clear All", 0, 0);
this.addWindow(this._customWindow);
}
this._secondCommandWindow.activate();
}
Scene_GambitMenu.prototype.exitSecond = function () {
this._secondCommandWindow.deactivate();
this._customCommandWindow.activate();
}
Scene_GambitMenu.prototype.update = function()
{
Scene_MenuBase.prototype.update.call(this);
if(Input.isTriggered("cancel")) SceneManager.pop();
}
function Window_GambitCustom() {
this.initialize.apply(this, arguments);
}
Window_GambitCustom.prototype = Object.create(Window_Base.prototype);
Window_GambitCustom.prototype.constructor = Window_GambitCustom;
Window_GambitCustom.prototype.initialize = function(x, y, width, height) {
Window_Base.prototype.initialize.call(this, x, y, width, height);
}
function Window_CustomCommand () {
this.initialize.apply (this, arguments);
}
Window_CustomCommand.prototype = Object.create (Window_Command.prototype);
Window_CustomCommand.prototype.constructor = Window_CustomCommand;
Window_CustomCommand.prototype.initialize = function (x, y) {
Window_Command.prototype.initialize.call (this, x, y);
}
Window_CustomCommand.prototype.makeCommandList = function() {
this.addCommand ("Add Slot", "addSlotCommand");
this.addCommand ("Swap Slot", "swapCommand");
this.addCommand ("Clear Slot", "clearCommand");
this.addCommand ("Clear All Slot", "clearAllCommand");
};
function Window_SecondCommand () {
this.initialize.apply (this, arguments);
}
Window_SecondCommand.prototype = Object.create (Window_Command.prototype);
Window_SecondCommand.prototype.constructor = Window_SecondCommand;
Window_SecondCommand.prototype.initialize = function (x, y) {
Window_Command.prototype.initialize.call (this, x, y);
}
Window_SecondCommand.prototype.makeCommandList = function() {
this.clearCommandList();
var numSlot = $gameVariables.value(22);
var numCommand = numSlot.length;
var bool;
for(var i = 0; i < numCommand; i++)
{
if(ownGlobalCommand == 1)
{
bool = false;
if(numSlot[i][0] == 0)
{
bool = true;
}
}
if(ownGlobalCommand == 2 || ownGlobalCommand == 3)
{
bool = true;
if(numSlot[i][0] == 0)
{
bool = false;
}
}
if(ownGlobalCommand == 4) //needs to be edited
{
bool = false;
if(numSlot[i][0] == 0)
{
bool = true;
}
}
this.addCommand ("Slot "+i+" "+numSlot[i][2], "slotCommand"+i, bool);
}
}
Window_SecondCommand.prototype.maxPageRows = function () {
return 10;
};
Window_SecondCommand.prototype.maxCols = function () {
return 1;
};
Window_SecondCommand.prototype.windowHeight = function () {
return 400;
};
Window_SecondCommand.prototype.windowWidth = function () {
return 800;
};
_alias_cursor_upmovement = Window_Command.prototype.cursorUp;
Window_SecondCommand.prototype.cursorUp = function () {
_alias_cursor_upmovement.call(this);
};
Window_SecondCommand.prototype.cursorDown = function () {
Window_Command.prototype.cursorDown.call(this);
this._customWindow.contents.clear(); //<<<<<<<<<<<<<<<<---------------The error
this._customWindow.drawText("DOWN", 0, 0);
this.addWindow(this._customWindow);
};
// Variable 21 - Is the array initialize? 0 if not, 1 if initialize
// Variable 22 - Lists of Gambit SLots. Parameters:
//[0] = Slot State: 0 - not used, 1 - used
//[1] = Item ID
//[2] = Item Name
//[3] = Item Fragment Type
// Fragment types: 1 - Weapon
// 2 - Skill
// 3 - Armor
//[4] = Positivity: 0 - Positive Slot
// 1 - Negative Slot
var initializeSlots = function ()
{
var numFragments = $gameParty.numItems($dataItems[15]); //get number of Gambit Slot Fragment in the inventory
//var numFragments = 100;
if(numFragments == 0)
{
//no fragments
}
else
{
var arraySlots = [];
var i = 0;
for(i = 0; i < numFragments; i++)
{
arraySlots[i] = [];
arraySlots[i][0] = 0;
arraySlots[i][1] = 0;
arraySlots[i][2] = 'EMPTY';
arraySlots[i][3] = 0;
arraySlots[i][4] = 0;
}
$gameVariables.setValue(21, 1);
$gameVariables.setValue(22, arraySlots);
}
}
//code para bigyan ang player ng Gambit Slot Fragment
var giveGambitSlotFragment = function (number)
{
//give the player the item
$gameParty.gainItem($dataItems[15], number);
//update the number of slots
var numFragments = $gameParty.numItems($dataItems[15]);
var numSlots = $gameVariables.value(22);
var newNum = numFragments - numSlots.length;
var x = numSlots.length;
console.log(numSlots);
for(var i = 0; i <= newNum; i++)
{
numSlots[x] = [];
numSlots[x][0] = 0;
numSlots[x][1] = 0;
numSlots[x][2] = 'EMPTY';
numSlots[x][3] = 0;
numSlots[x][4] = 0;
x++;
}
}
var giveGambitSlotFragmentLi = function (number)
{
$gameParty.gainItem($dataItems[15], number);
initializeSlots();
}