MV Yanfly YEP_ItemCore Bug

Hello, everyone!

I seem to be encountering a bug in Yanfly's "Item Core" plugin (YEP_ItemCore.js). The issue has been replicated in a clean (new) project with no other plugins enabled.

I am using Item Core v. 1.30 — This appears to be the latest version after checking Yanfly's website.

The error occurs when using the limited number of items param with the "updated scene item" param set to false. When using an item from the menu, such as a potion, the game crashes with the following error: "TypeError" - "Cannot read property 'name' of null"

Here is how to reproduce the bug:

1. Create a new project.
2. Add YEP_ItemCore to plugins.
3. Change "Max Items" param to some number (I've tried various numbers here, it doesn't seem to matter.)
4. Change "Updated Scene Item" to "false."
5. Click "OK," "Apply," and exit the plugins window.
6. Create an autorun event that gives the party at least 1 potion.
7. Add some kind of damage to a player or the entire party so you can use the potion on them.
8. Run the game.
9. Open the menu and use the potion on a damaged player.
10. "TypeError" - "Cannot read property 'name' of null"

Console Log:

rpg_managers.js:1949 TypeError: Cannot read property 'name' of null
at Window_ItemList.drawEquippedActor (YEP_ItemCore.js:1443)
at Window_ItemList.drawItemCarryNumber (YEP_ItemCore.js:1414)
at Window_ItemList.drawItemNumber (YEP_ItemCore.js:1400)
at Window_ItemList.drawItem (rpg_windows.js:1991)
at Window_ItemList.Window_Selectable.redrawItem (rpg_windows.js:1272)
at Window_ItemList.Window_Selectable.redrawCurrentItem (rpg_windows.js:1277)
at Scene_Item.useItem (rpg_scenes.js:1292)
at Scene_ItemBase.onActorOk (rpg_scenes.js:1136)
at Window_MenuActor.Window_Selectable.callHandler (rpg_windows.js:902)
at Window_MenuActor.Window_Selectable.callOkHandler (rpg_windows.js:1171)

Any help in squashing this is appreciated. Or, if I am somehow being silly and missing something obvious, please correct me gently. 🙂

Thank you in advance!
That function is trying to draw equipment that is currently equipped by the party members in the scene. Looking at it, it sets a variable to null, and then sets it to the current actor during some sort of equipment check.

If you edit the following line (1443)
var text = carrier.name();
to this:
var text = (carrier) ? carrier.name() : ''
It should stop that crash specifically.
@ramza Idont know what it does exactly, but when I change
carrier.name(); to actor.name(); it stops the crash too, but not
sure about scene change?

you function of (carrier) ? carrier.name : "" ; did the job too,
the result is kinda the same as changing it to actor.name(); =)
the result is kinda the same as changing it to actor.name(); =)
...kinda? I guess? Ramza's code will indicate (via the lack of the name) that this code returned an unexpected response.

Your change is going to make that function show the name of the last actor in the party everywhere in the game that function is called - without looking at it too deeply, I suspect that will show all of the equipment worn by the party as being equipped by that last actor.
That function is trying to draw equipment that is currently equipped by the party members in the scene. Looking at it, it sets a variable to null, and then sets it to the current actor during some sort of equipment check.

If you edit the following line (1443)
var text = carrier.name();
to this:
var text = (carrier) ? carrier.name() : ''
It should stop that crash specifically.

Thank you for the quick fix! I have implemented this code change and all seems well now.

To make sure I am understanding it correctly, as I have limited programming experience, the original code is assigning a value to var text (var text =) and it is trying to pull this value from carrier.name().

But, if carrier.name has no value assigned (null), the game crashes.

So, this new code implements an 'if' condition, such that 'if carrier.name()' is 'null,' the attempt to assign a value from it is skipped. Otherwise, if carrier.name() has an assigned value, it will perform the original code as written by Yanfly.

Am I getting this halfway right?

I definitely want to learn more about Javascript. Most of my experience (which is still quite minimal) is with C++ and Java, but not Javascript, specifically.

I feel like I can read a lot of the Javascript code but can't always write anything that makes sense with it. Still learning...

Thank you again for your help!
Thank you for the quick fix! I have implemented this code change and all seems well now.

To make sure I am understanding it correctly, as I have limited programming experience, the original code is assigning a value to var text (var text =) and it is trying to pull this value from carrier.name().

But, if carrier.name has no value assigned (null), the game crashes.

So, this new code implements an 'if' condition, such that 'if carrier.name()' is 'null,' the attempt to assign a value from it is skipped. Otherwise, if carrier.name() has an assigned value, it will perform the original code as written by Yanfly.

Am I getting this halfway right?

I definitely want to learn more about Javascript. Most of my experience (which is still quite minimal) is with C++ and Java, but not Javascript, specifically.

I feel like I can read a lot of the Javascript code but can't always write anything that makes sense with it. Still learning...

Thank you again for your help!
What we've done is replaced the assignment of the text variable with what is called a ternary operator. Basically, it is a one line if check (and you can nest them) where it checks the condition inside the brackets, and then does something depending on whether or not that condition is true or not.

In this case, our condition is (carrier), which is to check to see if the variable carrier is not falsey. What it ends up doing, is that in your specific case, that variable isn't set to be an actor, so it remained in the null state it started as, which is a falsey statement, which results in the ternary operator setting text equal to the value after the ':', which is a blank string (''). If the value isn't falsey, then the code is working as intended, so it sets text equal to the value between the '?' and ':', which is what it was before we change the line.

We use this very precise way of fixing the crash error to see if we can narrow down why it's crashing in the first place, but also, to insure that changing the line only affects it in a very specific case, so as to not modify whatever it was the function was supposed to be doing.

Since I didn't make the plugin, it's hard for me to know what is leading to the crash specifically, but the error stack you posted shows the exact line where it's happening, and what's causing it at that time, so we can work around it.

Without looking into it any further, I'd say the crash has something to do with your party members. I'd try removing everyone from the party, and then seeing if the crash still happens on the item menu, and if it doesn't, add everyone back one at a time to figure out which one is causing it.

Although, if that was really the cause, I'd expect the game to crash long before you made it into the item menu, probably on startup, or at least into the main menu.

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-yep_itemcore-bug.146795/