MZ Need help understanding some formatting RMMZ <<SOLVED>>

Its been figured it out. See edit at bottom if curious.

So I have every other obtain item setup to show the icon and the name of the item when it is gotten from a chest/breakable/searchable place. I'm trying to write a plugin that modifies the battle obtain item since its the only place that wont show an icon with the \I[x] type command.

I found this:
BattleManager.displayDropItems = function() {
const items = this._rewards.items;
if (items.length > 0) {
$gameMessage.newPage();
for (const item of items) {
$gameMessage.add(TextManager.obtainItem.format(item.name));
}
}
};
Im assuming based on my limited understand of Javascript that the $gameMessage.add is where I would need the add code but I cant seem to find the correct code to add the icon. Does anyone now where i can find mesage code formats I can look at?

Thanks

Edit:
For those who are curious, what I did was create a plug in with this change.

BattleManager.displayDropItems = function() {
const items = this._rewards.items;
if (items.length > 0) {
$gameMessage.newPage();
for (const item of items) {
$gameMessage.add(TextManager.obtainItem.format(item.iconIndex, item.name));
}
}
};

In the Database > Terms section I changed the Obtain Item message to \I[%1]%2 was found! The was found can be what ever you want your obtain item message to be.
By default text codes do work in the Obtain Item message, no edits needed. And yes, I just tested to be certain. Maybe check your plugins?

$gameMessage.add (rmmz_objects.js) puts the text in the message queue to be processed. All that text goes through Window_Message#updateMessage, which processes all text codes: the normal ones like \v[x] and \i[x], as well as the special message-only ones like \. and \^.

String#format (rmmz_core.js) just replaces %1, %2, etc with specific values. In this case, it replaces %1 from the Obtain Item text with the name of the item. If you wanted to add %2 = item icon index, you could change this line:

$gameMessage.add(TextManager.obtainItem.format(item.name));
...to this:

$gameMessage.add(TextManager.obtainItem.format(item.name, item.iconIndex));
In that case, I suggest you copy the whole BattleManager.displayDropItems method into a separate .js file, make that edit, then import the .js file as a plugin. This means you can turn your edit on/off at will, easily keep track of it and transfer it to other projects, and avoid it getting erased if/when you update your project's core scripts.

Alternatively, you could probably modify the drop item info, i.e. (untested):
Spoiler: plugin code suggestion
JavaScript:
/*:
 * @target MZ
 * @plugindesc Show icons for drop items.
 * @help Free to use and/or modify for any project, no credit needed.
 */
(alias => {
  Game_Troop.prototype.makeDropItems = function() {
    // get original drop item list
    const res = alias.apply(this, arguments);
    // loop through all original drop items
    for (let n = res.length; n--;) {
      // shallow copy (only want to change name, which is top-level)
      const item = Object.assign({}, res[n]);
      // change item name for display
      item.name = "\\i[" + item.iconIndex + "] " + item.name;
      // replace original item reference with edited copy
      res[n] = item;
    }
    return res;
  };
})(Game_Troop.prototype.makeDropItems);
This would be my personal preference, since it avoids a strict override.
By default text codes do work in the Obtain Item message, no edits needed. And yes, I just tested to be certain. Maybe check your plugins?

$gameMessage.add (rmmz_objects.js) puts the text in the message queue to be processed. All that text goes through Window_Message#updateMessage, which processes all text codes: the normal ones like \v[x] and \i[x], as well as the special message-only ones like \. and \^.

String#format (rmmz_core.js) just replaces %1, %2, etc with specific values. In this case, it replaces %1 from the Obtain Item text with the name of the item. If you wanted to add %2 = item icon index, you could change this line:

$gameMessage.add(TextManager.obtainItem.format(item.name));

...to this:

$gameMessage.add(TextManager.obtainItem.format(item.name, item.iconIndex));

In that case, I suggest you copy the whole BattleManager.displayDropItems method into a separate .js file, make that edit, then import the .js file as a plugin. This means you can turn your edit on/off at will, easily keep track of it and transfer it to other projects, and avoid it getting erased if/when you update your project's core scripts.

Alternatively, you could probably modify the drop item info, i.e. (untested):
Spoiler: plugin code suggestion
JavaScript:
/*:
 * @target MZ
 * @plugindesc Show icons for drop items.
 * @help Free to use and/or modify for any project, no credit needed.
 */
(alias => {
  Game_Troop.prototype.makeDropItems = function() {
    // get original drop item list
    const res = alias.apply(this, arguments);
    // loop through all original drop items
    for (let n = res.length; n--;) {
      // shallow copy (only want to change name, which is top-level)
      const item = Object.assign({}, res[n]);
      // change item name for display
      item.name = "\\i[" + item.iconIndex + "] " + item.name;
      // replace original item reference with edited copy
      res[n] = item;
    }
    return res;
  };
})(Game_Troop.prototype.makeDropItems);
This would be my personal preference, since it avoids a strict override.
Thanks for the reply I was just adding the item.iconIndex to the code. this makes me glad that i might just be learning more javascript. Thanks for the extra code info.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-understanding-some-formatting-rmmz-solved.148912/