write the last item removed to the variable.

I have been using a script created by Caethyril to delete random items.

I attempted to add this script, but it doesn't display the last item removed.
$gameVariables.setValue(36, [count]);

also, I am utilizing Yanfly's message core to show the item in the text box \ni[\V[36]].
Could you share a screenshot of the entirety of your code/eventing? It's much easier to see what you're doing wrong with the full context, though from a glance having count in brackets [] will throw an error and is likely the root of your problem.
When you say "display the last item" and "show the item," what do you mean? The item's name?

$gameVariables.setValue(36, [count]);
That's not correct JavaScript syntax for that variable and that method, and it also isn't doing what I think you want.

If you're trying to store the name of the item the party is losing, you'd modify the code @caethyril wrote thusly:
Code:
let items = $gameParty.allItems();
let count = items.length;
if (count)
{
    let lostItem = items[Math.randomInt(count)];
    $gameVariables.setValue(36, lostItem.name);
    $gameParty.loseItem(lostItem, 1);
}

from a glance having count in brackets [] will throw an error
No, it won't. You can put anything inside brackets and JavaScript will be just fine with it, instancing a single-element array containing that variable.

However, since count is the number of items being carried by the party, it has nothing to do with what the OP wants to do.
Could you share a screenshot of the entirety of your code/eventing? It's much easier to see what you're doing wrong with the full context, though from a glance having count in brackets [] will throw an error and is likely the root of your problem.

this is what I write
var items = $gameParty.allItems();
var count = items.length;
if (count) $gameParty.loseItem(items[Math.randomInt(count)], 1);
$gameVariables.setValue(36, [count]);

When you say "display the last item" and "show the item," what do you mean? The item's name?


That's not correct JavaScript syntax for that variable and that method, and it also isn't doing what I think you want.

If you're trying to store the name of the item the party is losing, you'd modify the code @caethyril wrote thusly:
Code:
let items = $gameParty.allItems();
let count = items.length;
if (count)
{
    let lostItem = items[Math.randomInt(count)];
    $gameVariables.setValue(36, lostItem.name);
    $gameParty.loseItem(lostItem, 1);
}


No, it won't. You can put anything inside brackets and JavaScript will be just fine with it, instancing a single-element array containing that variable.

However, since count is the number of items being carried by the party, it has nothing to do with what the OP wants to do.
Whoa, thank you!!! it's really worked.
Spoiler: image
image_2024-09-12_131632898.png
with that code, the ID of the item is the result of the randomization - and you never store that number anywhere, so you can't do anything with it.

you would need an additional temporary variable to store that number, or reorder your commands:

Code:
var items = $gameParty.allItems();
var count = items.length;
if (count) $gameVariables.setValue(36, Math.randomInt(count));
$gameParty.loseItem(items[$gameVariables.Value(36)], 1);

untested, I don't know if the correct code is getValue or Value or ?


edit: ninja'd

Original thread: https://forums.rpgmakerweb.com/threads/write-the-last-item-removed-to-the-variable.171848/