MZ VisuMZ MainMenuCore - Drawing Actors on Main Menu

The core plugin I'm working on is VisuMZ MainMenuCore. I'm using some borrowed/modified script from VisuMZ ItemsEquipsCore to draw actor sprites on the main menu. (Mind them clipping over parameters, I havn't adjusted their positions yet.)
1742011645010.png


Here is the complete code that I'm working with:

====================================================

// Declare Constants
const actor = arguments[0];
const rect = arguments[1];
const lineHeight = this.lineHeight();
const paramheight = this.gaugeLineHeight() + 8;
let x = 0;
let y = 0;
let width = this.innerWidth;
let height = this.innerHeight;
let hw = Math.floor(width / 2);
let hx = x + width - hw;
const actor0 = $gameParty.members() [0]
const actor1 = $gameParty.members() [1]
const actor2 = $gameParty.members() [2]
const actor3 = $gameParty.members() [3]
const actorMax = $gameParty.maxBattleMembers();
const actorWidth = Math.floor((width - 10) / actorMax);
const index = $gameParty.battleMembers().indexOf(actor);
const actorX = x + 20 + (index * actorWidth);
this.drawActorCharacter(actor0, 185 + (actorWidth / 2), 100, 0);
this.drawActorCharacter(actor1, 185 + (actorWidth / 2), 200, 0);
this.drawActorCharacter(actor2, 185 + (actorWidth / 2), 300, 0);

this.drawActorCharacter(actor3, 185 + (actorWidth / 2), 400, 0);

// Draw Actor Graphic
const gx = rect.x + (this.graphicType() === 'face' ? 1 : 0);
const gy = rect.y + (this.graphicType() === 'face' ? 1 : 0);
const gw = Math.min(rect.width, ImageManager.faceWidth);
const gh = Math.min(rect.height, ImageManager.faceHeight + 2);
this.drawActorGraphic(actor, gx, gy, gw, gh);

// Draw Status Stuff
const sx = rect.x + 150;
const sy = rect.y + rect.height / 2 - this.lineHeight() * 1.5;
const sx2 = sx + 180;
this.drawActorName(actor, sx - 3, sy - 25);
this.drawActorLevel(actor, sx - 3, sy + 60);
this.drawActorIcons(actor, sx, sy + lineHeight * 2);
this.drawActorClass(actor, sx -40 , sy + 90);

// Place Gauges
const sy2 = sy + lineHeight;
const gaugeLineHeight = this.gaugeLineHeight();
this.placeGauge(actor, "hp", sx - 3, sy + 10);
this.placeGauge(actor, "mp", sx - 3, sy + 40);
const roomForTp = (sy2 + gaugeLineHeight * 3) <= rect.y + rect.height;
if ($dataSystem.optDisplayTp && roomForTp) {
this.placeGauge(actor, "tp", sx2, sy2 + gaugeLineHeight * 2);
}

// Following Requires VisuStella MZ's Core Engine
// Draw Additional Parameter Data if Enough Room
const sx3 = sx2 + 180;
const sw = rect.width - sx3 - 100;
if (Imported.VisuMZ_0_CoreEngine && sw >= 300) {
const params = VisuMZ.CoreEngine.Settings.Param.DisplayedParams;
const pw = Math.floor(sw / 2) - 28;
let px = sx3 - 200
let py = rect.y + Math.floor((rect.height - (Math.ceil(params.length / 2) * gaugeLineHeight)) / 2);
let counter = 0;
const c1 = ColorManager.itemBackColor1(18);
const c2 = ColorManager.itemBackColor2(20);
const x = rect.x;
const y = rect.y;
const w = rect.width;
const h = rect.height;
for (const param of params) {
this.resetFontSettings();
this.drawParamText(px - 5, py, pw - 25, param, false);
this.resetTextColor();
this.contents.fontSize = 22;
const paramValue = actor.paramValueByName(param, true);
this.changeTextColor(this.textColor(4));
this.drawItemDarkRect(sx + 145, sy - 18, 225, 35, 2);
this.drawItemDarkRect(sx + 145, sy + 18, 225, 35, 2);
this.drawItemDarkRect(sx + 145, sy + 54, 225, 35, 2);
this.drawItemDarkRect(sx + 145, sy + 90, 225, 35, 2);
this.drawItemDarkRect(sx + 370, sy - 18, 225, 35, 2);
this.drawItemDarkRect(sx + 370, sy + 18, 225, 35, 2);
this.drawItemDarkRect(sx + 370, sy + 54, 225, 35, 2);
this.drawItemDarkRect(sx + 370, sy + 90, 225, 35, 2);
this.drawItemDarkRect(sx + 595, sy - 18, 225, 35, 2);
this.drawItemDarkRect(sx + 595, sy + 18, 225, 35, 2);
this.drawItemDarkRect(sx + 595, sy + 54, 225, 35, 2);
this.drawItemDarkRect(sx + 595, sy + 90, 225, 35, 2);
this.contents.drawText(paramValue, px + 150, py + 6, pw - 5, gaugeLineHeight, 'left');
this.contentsBack.gradientFillRect(x, y, w, h, c1, c2, true);
this.contentsBack.strokeRect(x, y, w, h, c1);
counter++;
if (counter % 3 === 0) {
px = sx3 - 200;
py += gaugeLineHeight + 12;
} else {
px += pw + 40;
}
}
}


====================================================


What the issue is:

It seems that if the party doesn't have 4 members, the game will crash when opening the menu, with an error "Cannot read property of 'CharacterName' of undefined". This makes sense since it's trying to pull/reference information that isn't there.

I need a way to make the code draw actors according to the number of party members, rather than the static code I have now which doesn't adjust dynamically.

I was trying to use "if" and "{else}" along with "$gameParty.members () = #" to have it adjust what was drawn based on the number of party members, but I can't seem to get the syntax right and wind up with either "Invalid assignment left-hand side" or some other error. Here is what I'd tried in place of the bold/underlined text in the code above.

====================================================

if $gameParty.members () = 4 {
this.drawActorCharacter(actor0, 185 + (actorWidth / 2), 100, 0);
this.drawActorCharacter(actor1, 185 + (actorWidth / 2), 200, 0);
this.drawActorCharacter(actor2, 185 + (actorWidth / 2), 300, 0);
this.drawActorCharacter(actor3, 185 + (actorWidth / 2), 400, 0);
} else {
if $gameParty.members () = 3 {
this.drawActorCharacter(actor0, 185 + (actorWidth / 2), 100, 0);
this.drawActorCharacter(actor1, 185 + (actorWidth / 2), 200, 0);
this.drawActorCharacter(actor2, 185 + (actorWidth / 2), 300, 0);
} else {
if $gameParty.members () = 2 {
this.drawActorCharacter(actor0, 185 + (actorWidth / 2), 100, 0);
this.drawActorCharacter(actor1, 185 + (actorWidth / 2), 200, 0);
} else {
this.drawActorCharacter(actor0, 185 + (actorWidth / 2), 100, 0);
}
}
}
====================================================

I don't know if you can use mutilple } else { like that, so it may be completely wrong. There may be a much simpler way to do this, and I'm all ears if thats the case. Coding isn't my forte but I've been able to figure a lot of stuff out through trial and error, but this one I just don't have the technical knowledge to know what I'm doing wrong. Any help is appreciated!
I figured it out - I removed that bit of code in bold/underline and just added this at the end of "// Draw Status Stuff"

"this.drawActorCharacter(actor, sx +150 , sy + 90);"

Now it works as it should and draws according to the number of party members, and doesn't crash when I have less than 4.

Original thread: https://forums.rpgmakerweb.com/threads/visumz-mainmenucore-drawing-actors-on-main-menu.176251/