Problem with checking whether player has X items?

Hello everybody.

A while ago I had the issue of trying to have the game check whether or not a player actually has enough items for a sidequest. For this, someone on here helpfully wrote a short line of code for me that allows me to check with an IF function if the player actually has the items required for the sidequest after they select the dialogue option for turning the items in.

why wont it play.png


This should result in the below line playing when the player has 6 or more of database item 44 in their inventory.
1757439917346.png


Here is the database item in question. I gave myself 99 of the item in question to test the quest out; However, the IF-function always returns a negative, as if I had less than 6 of the item in question, even though I have 99. What part of the code is wrong?
Um… that script call looks like it was written for VX Ace or earlier. In MV or MZ it should look like this:

JavaScript:
$gameParty.numItems($dataItems[44]) >= 6

It probably "returns a negative" because the script call crashes, the engine catches and suppresses the crash, and that's treated as a fail.
Alternatively you can use Control Variables -> Game Data -> Item to store the quantity in a variable, then check that variable. Not only does that avoid the need for scripting, it's also convenient if you want to show the current quantity in a message, e.g. You need 6 eggs, but you only have \v[12].

Original thread: https://forums.rpgmakerweb.com/threads/problem-with-checking-whether-player-has-x-items.180010/