MV Icons from note data?

I understand that adding note data such as:
<value: integer> will display in the meta tag and can be called, and I've had success using this, however.

I'm trying to develop a weakness/absorb/resist section to my bestiary script and I don't really need the text. The page is already laid out, but instead of trying to use trait information I was just going to manually enter the meta data.

What I tried:
Note tag:
Code:
<weakness: \\i[64]>

In Game_Enemy.prototype.setup:
Code:
this.weakness = $dataEnemies[enemyId].meta['weakness'] || null;

In Window_EnemyBookStatus:
Code:
this.drawTextEx(enemy.weakness, x, y);

The result is always undefined. If I enter this into the console, it shows the correct value:
Code:
$dataEnemies[1].meta['weakness']

I tried changing the value to something else, still comes back as undefined. Other values worked. What gives?
In Window_EnemyBookStatus:
ideally, you link to any involved plugins in the issue, but...
this.drawTextEx(enemy.weakness, x, y);
if the plugin youre using is referencing the enemy's database entry, then there is no weakness property. youve written them into the Game_Enemy but a$dataEnemy only hasmeta.weakness
I think your missing link is that enemy.weakness is not the same place as $dataEnemies[1].meta['weakness']. When you have enemy, as Robro33 said, that's a Game_Enemy, not the enemy data; to get the data, you need to call enemy().

Thus, try this instead of enemy.weakness:

JavaScript:
enemy.enemy().meta.weakness

EDIT: Ah, wait, I see you were trying to prepare things ahead of time to make the shorter version work. Then do what I said in the setup function instead, like this:

JavaScript:
this.weakness = this.enemy().meta.weakness;

It's also possible that the order of things is wrong, so if that still doesn't work, you should show your entire setup function.


Alternatively, as Robro33 said, it might be that enemy in your example actually is the database entry rather than the Game_Enemy, so you could try drawing enemy.meta.weakness || '' instead.

EDIT2: I checked the core EnemyBook plugin, and Robro33's guess is correct. Your change to the setup function is thus doing nothing useful. Just write the above in your drawTextEx call and you should be good.
function.

Alternatively, as Robro33 said, it might be that enemy in your example actually is the database entry rather than the Game_Enemy, so you could try drawing enemy.meta.weakness || '' instead.
This worked exactly as I wanted it to, I just don't understand why the other way didn't work. I followed a tutorial for Game_Actor though, and it states that it modifies the actor as it exists. I wonder if this doesn't work because Game_Enemy doesn't actively exist, if so, when would this be useful? I can't think of a time Game_Enemy.prototype.setup would exist outside of battle, but I would expect to use troop instead, wouldn't I?

Thanks though, you got me over that head scratcher.
Maybe the best way to think of it is that a Game_Enemy is an enemy that you're currently fighting. It can basically be thought of as existing only when you're actually in battle. (In fact, it technically exists outside of battle too, and just does nothing.)

So, the Enemy Book can't work with Game_Enemy, because they aren't set up when you're in the menu. In theory, it could probably set them up just for its own purposes, but as it turns out, it really doesn't need to (it just needs the information from the database), so it doesn't.
Additional question, trying to add SceneManager.push(Scene_EnemyBook) to Yanfly's menu core causes a crash. Any idea why I can't push this scene? Even if I try to push it from the console it returns Scene_EnemyBook is not defined. I'm used to C#, so I'm struggling to understand how if this function exists, that JS returns it doesn't exist. So frustrating. lol

For the YEP Main Menu bind, I used:
Code:
SceneManager.push.bind(SceneManager, Scene_EnemyBook)
You'll need to edit the plugin to make that work. Find these lines:

JavaScript:
    function Scene_EnemyBook() {
        this.initialize.apply(this, arguments);
    }

Cut-and-paste them down to the very bottom of the file, and your script call should now work.
I think putting the constructor at the bottom, outside of any local function, could work thanks to hoisting. An alternative would be to keep it where it is and manually define it on the global object, e.g.
JavaScript:
window.Scene_EnemyBook = function() {
    this.initialize.apply(this, arguments);
}

More details on scope in JavaScript here~
All plugins load in "script mode", so their top-level scope is global.

Original thread: https://forums.rpgmakerweb.com/threads/icons-from-note-data.180813/