this.drawActorFace - 'undefined is not a function' [Solved]

So I'm running into this problem on a plugin I'm trying to put together, and I can't figure out for the life of me why the code seems to be following all the way back to this.drawFace, yet throwing the 'undefined is not a function' error at it.

This is the code in question:

Spoiler
//=============================================================================
// Teamwork_Mentor Window
//=============================================================================

function Window_Teamwork_Mentor() {
this.initialize.apply(this, arguments);
};

Window_Teamwork_Mentor.prototype = Object.create(Window_Base.prototype);
Window_Teamwork_Mentor.prototype.constructor = Window_Teamwork_Mentor;

Window_Teamwork_Mentor.prototype.initialize = function(x, y) {
Window_Base.prototype.initialize.call(this, x, y, 200, 200);
this._actor = null;
};

Window_Teamwork_Mentor.prototype.setActor = function(actor) {
if (this._actor !== actor) {
this._actor = actor;
this.refresh();
}
};

Window_Teamwork_Mentor.prototype.drawFace = function(faceName, faceIndex, x, y, width, height) {
width = width || Window_Base._faceWidth;
height = height || Window_Base._faceHeight;
var bitmap = ImageManager.loadFace(faceName);
var pw = Window_Base._faceWidth;
var ph = Window_Base._faceHeight;
var sw = Math.min(width, pw);
var sh = Math.min(height, ph);
var dx = Math.floor(x + Math.max(width - pw, 0) / 2);
var dy = Math.floor(y + Math.max(height - ph, 0) / 2);
var sx = faceIndex % 4 * pw + (pw - sw) / 2;
var sy = Math.floor(faceIndex / 4) * ph + (ph - sh) / 2;
this.contents.blt(bitmap, sx, sy, sw, sh, dx, dy);
};

Window_Teamwork_Mentor.prototype.drawActorFace = function(actor, x, y, width, height) {
this.drawFace(actor.faceName(), actor.faceIndex(), x, y, width, height);
};

Window_Teamwork_Mentor.prototype.refresh = function() {
this.contents.clear();
if (this._actor) {
var w = this.width - this.padding * 2;
var h = this.height - this.padding * 2;
var y = h / 2 - this.lineHeight() * 1.5;
var width = w - 162 - this.textPadding();
this.drawActorFace(this._actor, 0, 0, 144, h);
// this.drawActorSimpleStatus(this._actor, 162, y, width);
}
};

I went ahead and redefined the Window_Base functions (drawActorFace and drawFace) but it didn't do any good. The only other section of the plugin that shows up in the debug error is this:
Spoiler
Scene_Teamwork.prototype.onActorOk = function() {
// this._actorWindow.processOk();
var mentor = $gameParty.members()[this._actorWindow.index()]._actorId;
this._mentorWindow.setActor(mentor);
this.hideSubWindow(this._actorWindow, this._selectWindow);
};
- and it just flags the 'this._mentorWindow.setActor(mentor);' call line. The whole flow of errors is:
Spoiler
TypeError: undefined is not a function
at Window_Teamwork_Mentor.drawActorFace (ZephAM_TeamworkSys.js:501)
at Window_Teamwork_Mentor.refresh (ZephAM_TeamworkSys.js:511)
at Window_Teamwork_Mentor.setActor (ZephAM_TeamworkSys.js:477)
at Scene_Teamwork.onActorOk (ZephAM_TeamworkSys.js:326)

Would love any help. Been banging my head against this for too long!
I wonder, what is line 501 in your script? What exactly is line 501? Is it the function definition? Or the this.drawFace line? If it's the this.drawFace line, console.log all parameters.
I found your problem.

In Scene_Teamwork.onActorOk, you have following line:
Code:
var mentor = $gameParty.members()[this._actorWindow.index()]._actorId;

The devil lies in how the variables are named.
Your variable is called "mentor", so you assume it's an actor of type mentor.
But the value you assign to it is called "_actorId", so it's an Id, not an actor.

I actually tried evaluating that line of code in RMMV, and the result is indeed a number, not an actor.

Later on in the code, you try to call actor.faceName() and actor.faceIndex(), but actor here is a number, not an actual actor, so obviously it wouldn't have a faceName or faceIndex function, hence your "undefined is not a function" error.

You need to fetch the actual actor, which you can do like this:
Code:
var mentor = $gameActors._data[$gameParty.members()[this._actorWindow.index()]._actorId];

Basically, after you get the actor Id, you fetch the actor with that Id.
Spoiler
I found your problem.

In Scene_Teamwork.onActorOk, you have following line:
Code:
var mentor = $gameParty.members()[this._actorWindow.index()]._actorId;

The devil lies in how the variables are named.
Your variable is called "mentor", so you assume it's an actor of type mentor.
But the value you assign to it is called "_actorId", so it's an Id, not an actor.

I actually tried evaluating that line of code in RMMV, and the result is indeed a number, not an actor.

Later on in the code, you try to call actor.faceName() and actor.faceIndex(), but actor here is a number, not an actual actor, so obviously it wouldn't have a faceName or faceIndex function, hence your "undefined is not a function" error.

You need to fetch the actual actor, which you can do like this:
Code:
var mentor = $gameActors._data[$gameParty.members()[this._actorWindow.index()]._actorId];

Basically, after you get the actor Id, you fetch the actor with that Id.

That did the trick!

I thought I was already pulling a number by using ._actorId, but apparently not properly. Considering how many other times I've used $gameActors.actor() other times in the plugin, you'd think I'd know better XD.

Appreciate the assist, Nolonar!

Original thread: https://forums.rpgmakerweb.com/threads/this-drawactorface-undefined-is-not-a-function-solved.94571/