MV SRD Hudmaker Actor Image Issue

I'm back with another problem trying to figure out this plugin.

I just finished making my custom actor portraits and trying to show them in battle HUD. To do this, I've done what SRD does in his tutorial video where I have $gameParty.members()[1].actorId() for the actorID part of HUD element and have $gameParty.members()[1] for the condition window to check if said party member exists. From a practical standpoint, this works. If said party member exists while testing the game, their portrait is displayed and if they don't exist, it's not.

However, some weird stuff is happening.


Spoiler: Screenshot
Screenshot 2025-02-20 14.06.01.png

On the Element Manager, I get shown an ERROR tag, and the HUD displays the placeholder portrait I have for Actor 1 in my database (Only when setting up the HUD, doesn't show while testing the game). On top of this, if I have a missing member in my party, the console keeps spitting up the following error: TypeError: Cannot read property 'actorId' of undefined and because it keeps giving out that error, the game lags almost to a standstill while I have the console open.

The error seems to be that because a party member doesn't exist, it's actorId cannot be read. But the HUD shouldn't be trying to access that actorId in the first place while the condition is false. At least, that's how it seems to work in the tutorial video SRD has up on youtube (though he never shows how things look while he has a member missing from party).

So...what exactly is going on here? How do I fix this?
Actor ID 1 = $gameParty.leader() or $gameParty.members()[0]

which is probably why you get the error.

if you see your condition, its red as its not met.
@ShadowDragon

I'm not super sure what you mean. The condition is supposed to be red, as that party member doesn't exist and so nothing should be shown. But in the screenshot, you can see that Actor 1's placeholder portrait is being shown instead and the console gives out errors.
it's shown always, but if you save and into battle, that face wont be there.

if its a battle member actor, that you need to set that as well.

this is a small reference I use:
Code:
$gameParty.leader()    - Party Leader

$gameParty.members()[0] - 1st Member or Leader
$gameParty.members()[1] - 2nd Member
$gameParty.members()[2] - 3rd member
$gameParty.members()[3] - 4th Member

// optional adding to see if its a battleMember:

$gameActors.actor(ID).isBattleMember()

// or as hud

BattleManager.actor() ? BattleManager.actor().index() === 0 : false

this can be useful to make the member always show up correctly as some
has actor as "guest" and cannot fight.

red condition is not met, if you set it to 0 on the first, it should be green.

first battle member that is selected = $gameParty.members()[0]
or $gameParty.leader() which is the member of the party.
@ShadowDragon

I know how to reference actors/party members. I don't want the condition to be green because that party member doesn't exist yet/at that point. I'm just trying to fix the console from spitting out error messages.
party members start from 0.

because the formation you have set is the members that is being showed.

if you have only 1 member in party, it always refer to $gameParty.members()[0]
and no 1 (as this is not refered to ACTOR ID.

$gameActors.actor(id) does refer to actor, but this isn't want you want during battle.
so refer to 0 for the first party member in battle.

if you have Alex, Felix, Jason, Maria and only Maria was there, it is member[0]
not member 3.
@ShadowDragon

Yes, I know that. I have it set up for member[0] as well. But I need to setup portraits for every possible member in the HUD so that it shows their portrait when they are in the party. The example I show in the screenshot is for a member that is not yet in the party, but it still needs to be set up so that it shows their portrait when they are.

It's pretty much how SRD sets it up in his own tutorial, but I keep getting errors in the console which is an issue.
the base $gameParty.leader() (this is always exist)
or $gameParty.members()[0]

2nd member
so for the HP: ${$gameParty.members()[1].hp / $gameParty.members()[1].mhp}
condition (for the faces: $gameParty.members()[1]

the faces are drawn from the actor faces, custom faces should swap automatically.
otherwise, I need to dig into for formation and the amount of actors you use.
@ShadowDragon

Yes, the party leader always exists and I'm not having any problems with that. The issue is with other party members when they don't exist.

I have $gameParty.members()[1]/[2]/[3] for the condition of other party member faces, but when those party members are not in the party, meaning their condition is not met, my console keeps spitting out error messages and that makes the console unuseable.
the long way and tedious can be the same location (depending on faces/actors)
to use this for each face.

$gameParty.members()[0] && $gameActors.actor(ID)

change ID to the actor ID.
to simplify this into a function to be called "functionName" could be ideal, but
there was a swap for BattleManager.actor() && BattleManager.actorId() === ID
for the current turn.

how many actors do you have, and can they change formation at any time?
if you have 4 max actor to obtain and formation, the scriptcall given could work,
but has to be on each face, while members 1 and actorID changes (1,2,3,4)
if the first 4 actors can battle only.

if you have far more, than a simple function to automate it could be easier.
but that require searching the code how the faces are drawn to add this to the
condition so formation chance works to grab the face correctly.
@ShadowDragon

I have around 7 actors, all of which can be in the party but the max party size is 4. But it can be less than 4 and that is when the issue arises.

What I don't understand is that I'm doing it exactly how SRD did in his tutorial and it doesn't seem like there were any problems there.


Code:
function Sprite_HUDFace() {
    this.initialize.apply(this, arguments);
}

Sprite_HUDFace.prototype = Object.create(Sprite_HUDObject.prototype);
Sprite_HUDFace.prototype.constructor = Sprite_HUDFace;

Sprite_HUDFace._label = "Actor Face";

/*
 * Get HTML for Sprite_HUDText manipulation
 */
Sprite_HUDFace.getHtml = function(data) {
    const value = data["Actor ID"];
    let condition = data["Condition"];
    const layer = data["Layer"];
    const width = data["Width"];
    const height = data["Height"];
    const color = data["Background Color"];
    const alpha = data["Background Alpha"];
    const mask = data["Mask"];

    const sele = ['', ''];
    if(mask === '0') sele[0] = 'selected';
    else if(mask === '1') sele[1] = 'selected';

    try {
        eval(condition);
    } catch(e) {
        data["Condition"] = '';
        condition = '';
    }

    return `${HUDManager.createTitle(data.id, Sprite_HUDImageText._label)}
            <table>
                ${HUDManager.createHeader()}
                ${HUDManager.createInput("Actor ID", value)}
                ${HUDManager.createConditionInput("Condition", condition)}
                ${HUDManager.createInput("Layer", layer)}
                ${HUDManager.createInput("Width", width)}
                ${HUDManager.createInput("Height", height)}
                ${HUDManager.createColor("Background Color", color, "Background Alpha", alpha)}
                ${HUDManager.createSelect("Mask", ["0", sele[0], "None"],
                                         ["1", sele[1], "Circle"])}
                ${HUDManager.createRefresh()}
            </table>`;
};

/*
 * Register Sprite_HUDImageText within the HUDManager
 */
HUDManager.typeNames.push(Sprite_HUDFace._label);
HUDManager.types[Sprite_HUDFace._label] = {
    class: Sprite_HUDFace,
    html: Sprite_HUDFace.getHtml,
    data: {
        "type":         Sprite_HUDFace._label,
        "Actor ID":     "$gameParty.leader().actorId()",
        "Condition":     "",
        "Layer":         "0",
        "Width":         "144",
        "Height":         "144",
        "Background Color": '#FFFFFF',
        "Background Alpha": "255",
        "Mask":         "1"
    },
    format: function(data) {
        let temp;
        try {
            temp = "Actor: " + String(eval(data["Actor ID"]));
        } catch(e) {
            temp = "ERROR";
        }
        if(temp.length > 12) temp = temp.substring(0, 12) + "...";
        return temp;
    }
}

Sprite_HUDFace.prototype.initialize = function(info) {
    Sprite_HUDObject.prototype.initialize.call(this, new Bitmap(1, 1), info);
    this.properties = ["Actor ID", "Layer", "Condition", "Width", "Height", "Background Color", "Background Alpha", "Mask"];
    for(let i = 0; i < this.properties.length; i++) {
        const prop = this.properties[i];
        this[prop] = info[prop];
    }
    this._value = this.getActorId();
    this._actor = $gameActors.actor(this._value);
    this._curFace = this._actor.faceName();
    this.refresh(true);
};

Sprite_HUDFace.prototype.getActorId = function() {
    let result;
    try {
        result = eval(this["Actor ID"]);
    } catch(e) {
        console.log('Error with Actor Face\n' + e);
        result = 1;
    }
    return result;
};

Sprite_HUDFace.prototype.update = function() {
    Sprite_HUDObject.prototype.update.call(this);
    if(!this._isVisible) return;
    const newValue = this.getActorId();
    if(this._value !== newValue || this._curFace !== this._actor.faceName()) {
        this._value = newValue;
        this.refresh(true);
    }
};

Sprite_HUDFace.prototype.refresh = function(refreshProperties) {
    Sprite_HUDObject.prototype.refresh.apply(this, arguments);
    this._oBitmap.addLoadListener(this.refreshBitmap.bind(this));
};

Sprite_HUDFace.prototype.refreshBitmap = function() {
    this.bitmap.clear();
    const color = _.convertHex(this["Background Color"], parseInt(this["Background Alpha"]));
    this.bitmap.fillRect(0, 0, this.bitmap.width, this.bitmap.height, color);
    this.drawFace(this._actor.faceIndex(), parseInt(this["Width"]), parseInt(this["Height"]));
    this.setupSnaps();
};

Sprite_HUDFace.prototype.drawFace = function(faceIndex, width, height) {
    width = width || Window_Base._faceWidth;
    height = height || Window_Base._faceHeight;
    var pw = Window_Base._faceWidth;
    var ph = Window_Base._faceHeight;
    var sx = faceIndex % 4 * pw + (pw - pw) / 2;
    var sy = Math.floor(faceIndex / 4) * ph + (ph - ph) / 2;
    this.bitmap.blt(this._oBitmap, sx, sy, pw, ph, 0, 0, width, height);
};

Sprite_HUDFace.prototype.refreshProperties = function() {
    Sprite_HUDObject.prototype.refreshProperties.apply(this, arguments);
    const bit = this.bitmap;
    const width = parseInt(this["Width"]);
    const height = parseInt(this["Height"]);
    this.resizeBitmap(bit, width, height);
    this.z = parseInt(this["Layer"]);
    this._value = this.getActorId();
    this._actor = $gameActors.actor(this._value);
    this._curFace = this._actor.faceName();
    this._oBitmap = ImageManager.loadFace(this._actor.faceName());
    this.refreshMask(width, height);
};

Sprite_HUDFace.prototype.refreshMask = function(width, height) {
    if(this._maskSprite) this.removeChild(this._maskSprite);
    this.createMask();
    this.refreshMaskBitmap(width, height);
    this.redrawMask();
};

Sprite_HUDFace.prototype.createMask = function() {
    this._maskSprite = new Sprite(new Bitmap(1, 1));
    this._maskSprite.anchor.set(0.5);
    this.mask = this._maskSprite;
    this.addChild(this._maskSprite);
};

Sprite_HUDFace.prototype.refreshMaskBitmap = function(width, height) {
    const spr = this._maskSprite;
    spr.bitmap.resize(width, height);
    spr._frame.width = 0;
    spr._frame.height = 0;
    if(_.isV150) {
        spr._refreshFrame = true;
        spr._onBitmapLoad(spr.bitmap);
    } else {
        spr._onBitmapLoad();
    }
};

Sprite_HUDFace.prototype.redrawMask = function() {
    const bit = this._maskSprite.bitmap;
    bit.clear();
    if(this["Mask"] === "0") {
        bit.fillRect(0, 0, bit.width, bit.height, "#ffffff");
    } else {
        bit.fillRect(0, 0, bit.width, bit.height, "#000000");
        const w2 = bit.width / 2, h2 = bit.height / 2;
        bit.drawOval(w2, h2, w2, h2, "#ffffff");
    }
};

This is the code in the HudMaker that is responsible for drawing the Actor Faces. I don't understand all of it but Line 97 is what makes the console log the error. I'm thinking maybe if I delete that line, it will fix the issue of breaking my console but I'm not confident that it won't cause more issues down the line.


Edit: Oh, it doesn't show the lines in the code. This part is what causes the error messages in the console:

Sprite_HUDFace.prototype.getActorId = function() {
let result;
try {
result = eval(this["Actor ID"]);
} catch(e) {
console.log('Error with Actor Face\n' + e);
result = 1;
}
return result;
that means that the actor isn't preset inside the party, so it throw that error which is normal.
as you see your condition, it's RED, not present so it cannot draw the face.

what you could do, is add the actors (1,2,3,4) and than create the huds, as if you remove it
on a debug, it won't be visible by than.

if you close the hud with that condition, it should be hidden as well.

filling your party is your best shot in creating the hud, so you can directly check if its
working correctly while the hud panel is off.

Original thread: https://forums.rpgmakerweb.com/threads/srd-hudmaker-actor-image-issue.175664/