MZ Changing notetag metadata for actor through a script call

First, I'm going to state the obvious, I really don't know coding too well. That said, I've been using Visustella ElementStatusCore and have managed to create a new entry using the following code:

Spoiler: Code
JavaScript:
// Declare Constants
const lineHeight = this.lineHeight();
const actor = this._actor;
const thirdWidth = Math.floor(this.innerWidth / 2);
const padding = 8
let x = 0;
let y = 0;

// Draw Actor Graphic
this.drawActorGraphic(0, this.innerWidth / 2);

// Declare Parameter Rect
let rect = new Rectangle(0, 0, thirdWidth, this.innerHeight);

// Create New Actor Information
Game_Actor.prototype.fullname = function() {
    const regex = /<fullname:\s*(\d+)>/i;
    const match = this.actor().note.match(regex);
    return match ? match[1] : 'Unknown';
};

Game_Actor.prototype.age = function() {
    const regex = /<age:\s*(\d+)>/i;
    const match = this.actor().note.match(regex);
    return match ? parseInt(match[1]) : 'Unknown';
};

Game_Actor.prototype.gender = function() {
    const regex = /<gender:\s*(.+)>/i;
    const match = this.actor().note.match(regex);
    return match ? match[1] : 'Unknown';
};

Game_Actor.prototype.hometown = function() {
    const regex = /<hometown:\s*(.+)>/i;
    const match = this.actor().note.match(regex);
    return match ? match[1] : 'Unknown';
};

// Draw Skill Types
x = rect.x;
y = 0;

this.resetFontSettings();
this.drawItemDarkRect(x, y, rect.width, lineHeight, 2);
        this.drawTextEx(`\\C[16]Full Name:\\C[0] ${actor.fullname()}`, padding, 0, this.contentsWidth(), lineHeight);
        y += lineHeight;
this.drawItemDarkRect(x, y, rect.width, lineHeight, 2);
        this.drawTextEx(`\\C[16]Class:\\C[0] ${actor.fullname()}`, padding, lineHeight, this.contentsWidth(), lineHeight);
        y += lineHeight;      
this.drawItemDarkRect(x, y, rect.width, lineHeight, 2);
        this.drawTextEx(`\\C[16]Age:\\C[0] ${actor.age()}`, padding, lineHeight * 2, this.contentsWidth(), lineHeight);
        y += lineHeight;
this.drawItemDarkRect(x, y, rect.width, lineHeight, 2);
        this.drawTextEx(`\\C[16]Gender:\\C[0] ${actor.gender()}`, padding, lineHeight * 3, this.contentsWidth(), lineHeight);
        y += lineHeight;
this.drawItemDarkRect(x, y, rect.width, lineHeight, 2);
        this.drawTextEx(`\\C[16]Hometown:\\C[0] ${actor.hometown()}`, padding, lineHeight * 4, this.contentsWidth(), lineHeight);
        y += lineHeight;
this.drawItemDarkRect(x, y, rect.width, this.innerHeight - y);

//

// Draw Weapon Types
rect.x += rect.width;
x = rect.x;
y = 0;
this.resetFontSettings();
this.drawItemDarkRect(x, y, rect.width, lineHeight, 2);
        this.drawText(`FillerText`, x + padding, 0, this.contentsWidth(), lineHeight);
        y += lineHeight;
        this.drawItemDarkRect(x, y, rect.width, lineHeight, 2);
        this.drawText(`FillerText`, x + padding, lineHeight, this.contentsWidth(), lineHeight);
        y += lineHeight;
        this.drawItemDarkRect(x, y, rect.width, lineHeight, 2);
        this.drawText(`FillerText`, x + padding, lineHeight * 2, this.contentsWidth(), lineHeight);
        y += lineHeight;
this.drawItemDarkRect(x, y, rect.width, this.innerHeight - y);

// Draw Armor Types
// rect.x += rect.width;
// x = rect.x;
// y = 0;
// rect.width = this.innerWidth - rect.x;
// this.resetFontSettings();
// this.drawItemDarkRect(x, y, rect.width, lineHeight, 2);
        // this.drawTextEx(`\\C[16]Age: \\C[0]${actor.age()}`, 24, 0, this.contentsWidth(), lineHeight);
        // y += lineHeight;
        // this.drawItemDarkRect(x, y, rect.width, lineHeight, 2);
        // this.drawText(`Race: ${actor.race()}`, 24, lineHeight, this.contentsWidth(), lineHeight);
        // y += lineHeight;
        // this.drawItemDarkRect(x, y, rect.width, lineHeight, 2);
        // this.drawText(`Hometown: ${actor.hometown()}`, 24, lineHeight * 2, this.contentsWidth(), lineHeight);
        // y += lineHeight;
// this.drawItemDarkRect(x, y, rect.width, this.innerHeight - y);

It works just fine, though obviously quite messy and very WIP. When I add the <blah: blah> tages to an actor's notefield they show up properly as I want them to. However now I am attempting something else. I would like to, for example, change the metadata through a script call.

I've tried running the following in a scriptcall to test,

Code:
$gameActors.actor(1).actor().meta.Age = 25;

However I'm not seeing any changes in the status window. Nor do any errors come up in the dev console.

Am I going about this the wrong way? Is it just that I'm missing something simple? Or do I need to do some much heavier lifting to get the desired result?

I want to thank everyone for reading this post, and for any help I can receive on this.
Metadata (notetags) are stored in the database, not on individual game objects. And the database is loaded one time, when the game boots.

You can, syntactically, do what you are trying to do, but it will only change any values temporarily. As soon as the player quits and reboots the game, they'll reset.

Additionally, many plugins have loaders that parse notetags into their own internal systems, so you changing the notetags during play (even temporarily, as described above) would have no effect.

For something like what you're doing above, it would make much more sense to me for you to simply store the age for each actor in one of your regular game variables. Or, if there's some reason that's cumbersome and you want to rely on script calls, you can store it directly on the actor: $gameActors.actor(3).age=25 and that will be written into the save file.

But I think it makes the most sense just to use regular variables that you can access and manipulate with event commands. I don't see any reason to outsource this into notetags in the first place.
The reason it's not working is because your Game_Actor.prototype.age function isn't reading the meta property to begin with. You've got it directly parsing the note for a regex match. To convert it to use the meta property instead, changing that function to something like this should work:
JavaScript:
Game_Actor.prototype.age = function() {
    return this.actor().meta.Age?.trim() ?? 'Unknown';
};

Then your proposed script call should properly change the value on your screen. However, as ATT_Turan said, the changes would be lost once the player exits the game.

Is it correct to assume that you're wanting to use a note tag to define the actor's starting age, but then you want to be able to persistently manipulate it afterward? If so, in what way do you intend to manipulate it (i.e. will you be incrementing/decrementing, or just straight up assigning it a new value)?
First of all, I want to thank both of you. With some trial and error I have managed to come up with a solution.

The reason it's not working is because your Game_Actor.prototype.age function isn't reading the meta property to begin with. You've got it directly parsing the note for a regex match. To convert it to use the meta property instead, changing that function to something like this should work:
JavaScript:
Game_Actor.prototype.age = function() {
    return this.actor().meta.Age?.trim() ?? 'Unknown';
};

Then your proposed script call should properly change the value on your screen. However, as ATT_Turan said, the changes would be lost once the player exits the game.

Is it correct to assume that you're wanting to use a note tag to define the actor's starting age, but then you want to be able to persistently manipulate it afterward? If so, in what way do you intend to manipulate it (i.e. will you be incrementing/decrementing, or just straight up assigning it a new value)?

I provided age as an example of several pieces of biographical information I am attaching to actors to display on their status screen. An actor, for example, whose hometown may start off unknown, and later identified through story progress. Or, yes, perhaps an actor going through a time skip.

Most importantly I am always trying to improve my understanding of javascript, and I have often found simply trying to do things, breaking them, and learning how to fix them to be helpful--and as is the case here, see just how badly I broke it, or how silly my implementation was, and get useful feedback.

But, again, I want to thank both of you. I have come up with a solution, and I have completely axed the use of notetags because of ATT_Turan's advice.
First of all, I want to thank both of you. With some trial and error I have managed to come up with a solution.



I provided age as an example of several pieces of biographical information I am attaching to actors to display on their status screen. An actor, for example, whose hometown may start off unknown, and later identified through story progress. Or, yes, perhaps an actor going through a time skip.

Most importantly I am always trying to improve my understanding of javascript, and I have often found simply trying to do things, breaking them, and learning how to fix them to be helpful--and as is the case here, see just how badly I broke it, or how silly my implementation was, and get useful feedback.

But, again, I want to thank both of you. I have come up with a solution, and I have completely axed the use of notetags because of ATT_Turan's advice.
Well, using note tags isn't necessarily a bad thing. Organizationally, it can make a lot of sense to define data regarding an actor in an actor's entry in the database. It makes it easy to keep track, easy to edit, and easy to add more actors later without having to create a bunch of new variables and whatnot. There are cases where using game variables would be better, and there are cases where using game variables would be more hassle for no real benefit. The best way to go about things just kinda depends on how you intend to use that data.

But just to toss out an example of you how could modify your original method in order to use note tags but still have the data be editable later:
JavaScript:
Game_Actor.prototype.hometown = function() {
    this._hometown ??= this.actor().meta.hometown?.trim() ?? 'Unknown';
    return this._hometown;
};

That will take whatever is in the database for it's initial value, but then you can permanently edit the value later like this:
JavaScript:
$gameActors.actor(1)._hometown = 'Butt Town';

Original thread: https://forums.rpgmakerweb.com/threads/changing-notetag-metadata-for-actor-through-a-script-call.157441/