Trying to change a value upon a certain character using an item?

Hey hey,
So I'm trying to do something where any character can use a consumable item, but using it on one particular character triggers a change in a variable. I've patched together a snippet of code, but it doesn't seem to be doing anything- maybe I'm not using the right syntax, or maybe I'm just going about it completely wrong, I'm not sure, but I'm a total beginner to JS, so any help at all would be appreciated.
Code:
if ($gameActors.actor(1) .consumeItem) {
$gameVariables.setValue(18, 3);
}
Thank you!
Looks like consumeItem is a function which is a truthy value in JS. When the if statement is executed variable 18 will always be set to the number 3. If you're not seeing 3 then the statement isn't being executed so there's one part you might have to troubleshoot. Is there more code to this?
Well, there certainly arent any 3s showing up in that variable...I wonder why it isn't executing? I have it set as a common event called when the item is used. Should I put it in the item's note tags instead?
Aha! I got it to work! For future reference: I had to nest it in another conditional branch to check that the actor was in the party first. Thanks for your help!
wait- no, it doesn't only work on the one character. Hmmm. This is tricky.
I'd recommend Yanfly's Skill Core plugin here, if you're not using it already. It offers a set of <[Phase] Eval> tags that let you run JS code on use of the corresponding skill or item. Tested it with the following and it seemed to work:
Code:
<After Eval>
if (target.isActor() && target.actorId() === 1) {
  $gameVariables.setValue(18, 3);
}
</After Eval>
This will set variable #18's value to 3 immediately after being used on actor #1; change the values as appropriate.
I was having the item call a common event with the script in it upon use. Does the script only work in battle? It won't let me use it on the field, unless I'm just doing something wrong- the code you gave me goes in the item's notes, right? Sorry for being so needy about this, ugh.
Yes, just put it in the item's notebox. Also, before you test, be sure to save your project after importing the Skill Core plugin. =)
Hm- I believe you, but it won't let me use any skill or item with the code applied...I'm really sorry to keep hassling about this!
It's OK, happy to help out! ^_^

By default, MV disallows use of items if the item would have no effect, e.g. you can't use a healing potion on someone at full HP. (It's kinda annoying, I'll look into it.) I tested using an item that applied silence to the target, and it worked (and set the variable if used on actor #1) on the map and in battle. If that works for you, maybe you could just make an invisible state that does nothing and apply that when you use the item? 😅

Otherwise, what other plugins (if any) are you using?

Edit: @SpitBlaze 👋 I'm heading off for now, need some sleep. 😴 Will check back tomorrow!
Aha, that did it! Thank you so much for this, you're a total lifesaver! I should've just tried doing that before, haha. Thank you so much!!
Well, it's not the most obvious thing to try. =P

Happy RPG Making! 🙏

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-change-a-value-upon-a-certain-character-using-an-item.92602/