$gameParty.lastItem() Returns previous item, not most recently consumed item

Hello All,

I am having some trouble with a CommonEvent sequence I am making. I am trying to add item effects with CE switches, waits, etc. However, I am having some trouble with the item triggering the "Item Effect" Common event which then tests if the item id matches the $gameParty.lastItem(). Currently, the last item keeps recalling the previous item used, not the most recently consumed item which has the effect to call the CE. Is there a better script to use? I also tried using "$gameTemp.lastActionData(type)" but was unable to get it to work. (Pictures included)

Thank you!
You don't call lastItem like that. It is a function that takes no arguments and returns the item itself, not the id.

So the script call you're after is $gameParty.lastItem().itemId() == 29
You can also control variable x to "Game Data" > Last > Last Used Item.
Then set conditional branch if variable x = (item number).
You don't call lastItem like that. It is a function that takes no arguments and returns the item itself, not the id.

So the script call you're after is $gameParty.lastItem().itemId() == 29
THANK YOU! That is exactly what I was after. My apologies, I am still new to JS and learning. Thank you for your advice!

*Edit* I tried utilizing that script call and now the switches don't turn on at all as opposed to all of them being activated previously under the "Item Effect" CE.
Please show screenshots of your new event.

Also try the suggestion from @NaosoX - if there's already a way to do it in the editor, it might be better to go with that.
You can also control variable x to "Game Data" > Last > Last Used Item.
Then set conditional branch if variable x = (item number).
Like this? I then have an If Variable 16 = (Last item), activate switch. However, there still seems to be no effect.
Please show screenshots of your new event.

Also try the suggestion from @NaosoX - if there's already a way to do it in the editor, it might be better to go with that.
My apologies, here is a screenshot. All other pages have remained the same. When item is consumed, the effect triggers the pictured CE. I did change the flow to a string of If/Else statements to hopefully organize the flow a little better ( I did this after trying the original setup as well with the pictured script calls. I also tried === instead of == with no change as well)
Like this? I then have an If Variable 16 = (Last item), activate switch. However, there still seems to be no effect.
That's not what NaosoX said. You're still using the script call, but he told you where to actually find it in the editor:
You can also control variable x to "Game Data" > Last > Last Used Item.

My apologies, here is a screenshot. All other pages have remained the same. When item is consumed, the effect triggers the pictured CE. I did change the flow to a string of If/Else statements to hopefully organize the flow a little better ( I did this after trying the original setup as well with the pictured script calls. I also tried === instead of == with no change as well)
For your purpose here, there is no difference between == and ===. There are, however, what appear to be errors in your other events.

It does look like you're doing stuff with script fields that you don't need to use scripts for, and not quite understanding it you're doing it incorrectly.

For example, how would we know if the Poppy switch activated correctly? You have two conditionals in the Seduction Vrb event:
if Poppy-1 is ON
So the first part will only do anything if Poppy and that other switch are on. Then you have:
if variable 3 == 5 * variable 3
The only time that could ever be true (and execute the rest of your code) is if the value of variable 3 is 0. What is that supposed to be checking? Why aren't you using a regular event command Conditional for it?

I expect your switches are turning on correctly, but the code resulting from them is broken and therefore not doing anything.
That's not what NaosoX said. You're still using the script call, but he told you where to actually find it in the editor:



For your purpose here, there is no difference between == and ===. There are, however, what appear to be errors in your other events.

It does look like you're doing stuff with script fields that you don't need to use scripts for, and not quite understanding it you're doing it incorrectly.

For example, how would we know if the Poppy switch activated correctly? You have two conditionals in the Seduction Vrb event:
if Poppy-1 is ON
So the first part will only do anything if Poppy and that other switch are on. Then you have:
if variable 3 == 5 * variable 3
The only time that could ever be true (and execute the rest of your code) is if the value of variable 3 is 0. What is that supposed to be checking? Why aren't you using a regular event command Conditional for it?

I expect your switches are turning on correctly, but the code resulting from them is broken and therefore not doing anything.
I see what you mean now. I now see that the Game data is an available option in the Control Variable event command. I have made that change it now appears to be working. I made the If/Else with Poppy-1 as a first check to see if the plant has been consumed previously that day as to limit it to once-per-day which also appears to now be working once making the change to use Game Data.

The "$gameVariables.value(3) == 5*$gameVariables.value(3)" script was suppose to be checking 5 changes in the Minute variable (Variable 3) as a replacement for using 18x 999 waits. Is this also an incorrect usage? I just recently added it after finding a similar forum post to substitute an internal CE timer
The "$gameVariables.value(3) == 5*$gameVariables.value(3)" script was suppose to be checking 5 changes in the Minute variable (Variable 3) as a replacement for using 18x 999 waits. Is this also an incorrect usage?
I'm sorry, but I just don't understand what you mean.
What you have typed there is a mathematical equation. $gameVariables.value(3) just means the value of variable 3. So that it's more familiar to things you'll have seen in, say, math class, let's replace it with X.

So that line is asking: "is X equal to 5 * X"? And the only time that could ever be true is if X = 0 (so that 5 * X is also 0).

If you want the event to wait, you should use Wait, putting something in a conditional won't prevent a parallel event from processing 60 times per second.
I just recently added it after finding a similar forum post to substitute an internal CE timer
Perhaps you can link to the post you got it from, and we can either explain what you misunderstood or say that original post also did something wrong.
I'm sorry, but I just don't understand what you mean.
What you have typed there is a mathematical equation. $gameVariables.value(3) just means the value of variable 3. So that it's more familiar to things you'll have seen in, say, math class, let's replace it with X.

So that line is asking: "is X equal to 5 * X"? And the only time that could ever be true is if X = 0 (so that 5 * X is also 0).

If you want the event to wait, you should use Wait, putting something in a conditional won't prevent a parallel event from processing 60 times per second.

Perhaps you can link to the post you got it from, and we can either explain what you misunderstood or say that original post also did something wrong.
I guess who I read the script call as when Variable x == 5*x (changes 5 times), then trigger the following event commands. But I very easily could have misinterpreted that from this forum post:


I also tried using waits but ran into an issue of other event processing stopping even when the CE is parallel. I also tried Wait in a movement route but it would simply skip over it and immediately change the modified variables back to 0. I may have to look further into why that might occur in other posts.
But I very easily could have misinterpreted that from this forum post:
That's a weird thread. But even there, the very next post after the code you're trying to use says it doesn't work.
I also tried using waits but ran into an issue of other event processing stopping even when the CE is parallel.
If everything is written correctly, that won't happen. If events are supposed to happen at the exact same time, the interpreter will alternate commands between them, so you won't be able to perceive any delay. Putting a Wait command in a parallel event will only stop itself from being run for that much time, which is very important for avoiding unnecessary processor usage leading to lag.

It sounds like you may need to post your related events and describe clearly what you're trying to do - there were several errors in this one, so there's a decent chance one of the other events has something that's causing your problems.

There are also a number of eventing tutorials available in forum posts and YouTube videos you could work through, if you haven't already. I think it's a good idea to make sure you're building understanding in a logical way, not just finding solutions and trying to paste them in 🙂
That's a weird thread. But even there, the very next post after the code you're trying to use says it doesn't work.

If everything is written correctly, that won't happen. If events are supposed to happen at the exact same time, the interpreter will alternate commands between them, so you won't be able to perceive any delay. Putting a Wait command in a parallel event will only stop itself from being run for that much time, which is very important for avoiding unnecessary processor usage leading to lag.

It sounds like you may need to post your related events and describe clearly what you're trying to do - there were several errors in this one, so there's a decent chance one of the other events has something that's causing your problems.

There are also a number of eventing tutorials available in forum posts and YouTube videos you could work through, if you haven't already. I think it's a good idea to make sure you're building understanding in a logical way, not just finding solutions and trying to paste them in 🙂
Thank you for your help! I did go over some more Youtube tutorials and began some basic lessons in JS coding to help with understanding plugins a little better. I simplified the code to a single common event that triggers when any item is consumed. ( see attached). This appears to have fixed some of the previous problems. I did have to make it a none-parallel process to work.

One drawback of making it non-parallel is the wait times not working. I have tried using the movement route as a timer for the variable effects (pictured in attachment) but it does not appear to work. The last item variable appears to be working but the effects do not. I am trying to have it jump to the item last consumed, check if it has been consumed before (item name switch), and if it has say "I shouldn't overdue it" else to run the variable effects. I am truly not sure about what is going wrong since logically it appears to flow correctly (intuitively)
One drawback of making it non-parallel is the wait times not working.
You're calling a move route on a common event that has no map presence, and therefore can't move.

It should work if you switch the target of the move route to be the player, or if you simply use the Wait event command on tab 2.

As a bit of unsolicited advice...why on Earth are you putting such a long wait in? If I were playing a game and I activated an item and my game stopped doing anything for over a minute, I would presume it froze up and quit.

And if it kept happening, I'd assume the game maker screwed something up, the game was glitched, and I'd uninstall it. There's no way I'd ever sit there long enough to get through the amount of wait time you have there.
You're calling a move route on a common event that has no map presence, and therefore can't move.

It should work if you switch the target of the move route to be the player, or if you simply use the Wait event command on tab 2.

As a bit of unsolicited advice...why on Earth are you putting such a long wait in? If I were playing a game and I activated an item and my game stopped doing anything for over a minute, I would presume it froze up and quit.

And if it kept happening, I'd assume the game maker screwed something up, the game was glitched, and I'd uninstall it. There's no way I'd ever sit there long enough to get through the amount of wait time you have there.
I did try switching the target to the player. However, like you mentioned this would either freeze the player for the 5min (18x999 frames) or would immediately skip the movement route and go right to changing the variable back to the original value (0 -> 5 -> 0). I am trying to have it so the item effects are substantial in real time (1 min, 5 min, etc). I wasnt able to find any plugins to make an alternative timer that would work for this, similar to Galv's EventTimer but for commonevents.
I am trying to have it so the item effects are substantial in real time (1 min, 5 min, etc).
This is the wrong way to try to do that.

Make a second common event with a parallel trigger and the switch of Poppy.

In that event, you put whatever length of time you want as the event command Wait. Then you display the message about poppy wearing off, turn off the poppy switch.

Then in the original event you've been working on, you get rid of all of that, and the only thing you do there in your Else branch is turn on the Poppy switch.

Parallel events don't stop the player from playing the game while they're running (they run in parallel), so you can make them Wait without freezing the character. Again (because you said it again in your last post) not a move route. The actual Wait command.

Original thread: https://forums.rpgmakerweb.com/threads/gameparty-lastitem-returns-previous-item-not-most-recently-consumed-item.143625/