Save Item ID as Variable

I’ve been toying with script calls but I can’t get this idea to work right. (This uses Yanfly’s Action Sequence plugin, incidentally)

I’m trying to add a skill called Synthesis, where the party member duplicates the effect of the last item which was used, for free. I know more or less how I want it to work:

-Each item has a common event that sets a variable to that item’s ID. I currently have it set the variable to
this.item().id

-The skill Synthesis uses the Action Sequence plugin to copy the effect of that item. I currently have it set to
<action copy: item:v[13]>

When I test it, it crashes when I use the item, and I’d like to know how to properly pull this off.

EDIT: I decided to instead give each item a script call that directly changes the variable, but now the Synthesis action does nothing. I did have the idea of a workaround, where I add 1 of that item to inventory and then Force Action to use said item, but Yanfly’s battle system gets screwy when Force Action is involved.
What was the crash when you tried it the first way? Can you provide screenshots of your setup?
-The skill Synthesis uses the Action Sequence plugin to copy the effect of that item. I currently have it set to
<action copy: item:v[13]>
I don't believe this is acceptable syntax. You're combining an action sequence command (which is essentially its own language) with syntax that is specific to damage formulae (the v[13]).

The instructions say:
<action copy: x:y>

Replace x with "item" or "skill" to set the type...The integer y is then the ID...For example...<action copy: skill:45>

v[13] is not an integer, it's a JavaScript reference (and one that's only recognized inside of a damage formula).

I'll have to ponder about how you might achieve this (if nothing else, that command could be modified to accept a JavaScript eval), but what you're trying to do is definitely incorrect per Action Sequences.
Promblem1.png
I don't believe this is acceptable syntax. You're combining an action sequence command (which is essentially its own language) with syntax that is specific to damage formulae (the v[13]).

The instructions say:


v[13] is not an integer, it's a JavaScript reference (and one that's only recognized inside of a damage formula).

I'll have to ponder about how you might achieve this (if nothing else, that command could be modified to accept a JavaScript eval), but what you're trying to do is definitely incorrect per Action

With fanfly plugins, you can mostly use \v[x] or v[x] in plugin commands and notetags and such.

If that doesn't work, you can always try $gameVariables.value(x) which works in most lunatic stuff.

I have to test to see which method works in this case though, but using variables to determine ID of anything is something I use a lot. I. Sure that is possible...

Finding the I'd of last item used... now that is a real challenge.
I’m fairly sure I can set the variable easily by a script call in each item’s damage formula, but neither v[x] nor \v[x] is having the desired effect.
V[x] =1 should work for item 1, v[x] =2 for item 2, etc etc,

Edit: x is replaced with the variable ID of course.
With fanfly plugins, you can mostly use \v[x] or v[x] in plugin commands and notetags and such.

If that doesn't work, you can always try $gameVariables.value(x) which works in most lunatic stuff.
This is not a "lunatic" field. Per the instructions I quoted above, it is expecting you to type a number, it's not evaluating JavaScript.

In my experience, Yanfly is quite clear in documenting which fields can accept code.

neither v[x] nor \v[x] is having the desired effect.
Aside from my prior answer, \v would additionally not be correct, as the slash is an escape code used in text windows.
Are you using outdated yanfly plugins? Pretty much all of them got an update like this:
- Bypass the isDevToolsOpen() error when bad code is inserted into a script
call or custom Lunatic Mode code segment due to updating to MV 1.6.1.
Are you using outdated yanfly plugins? Pretty much all of them got an update like this:
How would that be relevant? The OP is not using a script call or Lunatic Mode segment. They've mis-formatted an action sequence command. Am I misunderstanding something?

@VillainFan42 What you're looking at is on line 1499 of the Battle Engine Core (and 1501 for skills). The trick is I'm not familiar with regular expressions, so I'll suggest something but it might not work correctly. If this doesn't work, let us know and maybe eomere or @Trihan can fix it.

Edit line 1499 to say:
Code:
target = eval(RegExp.$2);

Save the file, refresh it in your plugin manager, try it in a play test using action copy:item:$gameVariables.value(13).
How would that be relevant? The OP is not using a script call or Lunatic Mode segment. They've mis-formatted an action sequence command. Am I misunderstanding something?
It was more meant as a side note. It didn't have any direct influence on their current problem, but may cause others later down the line. For example the line numbers you gave them may not match the ones from their plugin version 🙂
It was more meant as a side note. It didn't have any direct influence on their current problem, but may cause others later down the line. For example the line numbers you gave them may not match the ones from their plugin version 🙂
Yeah, the line numbers don’t quite match. Line 1499 wound up being a single } and changing what I thought was the right one screwed up the whole thing.
Yeah, the line numbers don’t quite match. Line 1499 wound up being a single } and changing what I thought was the right one screwed up the whole thing.
Okay...so re-download the current version, then apply the change I said.

Is your project up to date? You can get weird errors if your project version doesn't match what plugins are expecting. Current for MV is 1.6.1 (or .2).
Okay...so re-download the current version, then apply the change I said.

Is your project up to date? You can get weird errors if your project version doesn't match what plugins are expecting. Current for MV is 1.6.1 (or .2).
MV version is 1.6.1, Battle Engine plug-in version is 1.50
MV version is 1.6.1
That's not quite the same thing. The version of the editor doesn't necessarily match the version of the project - if you started it a long time ago, and the editor received updates, but you didn't manually patch the core scripts, your project could be an older version.

If you open your Game.rpgproject in a text editor, it should say which version your project is. If it's not 1.6.1 or .2, you can look at any of the threads about version updates to see the instructions to manually patch your project.

In the meantime, there's no immediate reason to think anything is malfunctioning with your project version, so you can update your Battle Engine and try my patch for your action sequence.
Update: I got the plug-in updated but it’ll be a while before I can test it out again. Real life stuff, you know.
How would that be relevant? The OP is not using a script call or Lunatic Mode segment. They've mis-formatted an action sequence command. Am I misunderstanding something?

@VillainFan42 What you're looking at is on line 1499 of the Battle Engine Core (and 1501 for skills). The trick is I'm not familiar with regular expressions, so I'll suggest something but it might not work correctly. If this doesn't work, let us know and maybe eomere or @Trihan can fix it.

Edit line 1499 to say:
Code:
target = eval(RegExp.$2);

Save the file, refresh it in your plugin manager, try it in a play test using action copy:item:$gameVariables.value(13).
I finally tried this and I’m sorry to say, nothing happened. I’m honestly considering just scrapping the idea altogether and finding something to replace it.
Uhm... I believe action sequences can trigger common events? That should make it possible to gain the last used item, right?
@ATT_Turan 's suggestion unfortunately cannot work, as the variable will be looked at but only once when the database is loaded. Whatever value the variable has at that point in time (presumably undefined) will be the source for the action copy.

However looking at that problem gave me another idea. <Custom Execution> notetags from the skills core should get evaluated before any action sequence takes place, right? So we should be able to use that to copy an action sequence, I think.
JavaScript:
<Custom Execution>
    $dataSkills[x].setupActions = $dataItems[$gameVariables.value(y)].setupActions.slice();
    $dataSkills[x].wholeActions = $dataItems[$gameVariables.value(y)].wholeActions.slice();
    $dataSkills[x].targetActions = $dataItems[$gameVariables.value(y)].targetActions.slice();
    $dataSkills[x].followActions = $dataItems[$gameVariables.value(y)].followActions.slice();
    $dataSkills[x].finishActions = $dataItems[$gameVariables.value(y)].finishActions.slice();
</Custom Execution>

Replace x with the id of your item copy skill and ywith the id of the variable you are using to track the last used item.
ATT_Turan's suggestion unfortunately cannot work, as the variable will be looked at but only once when the database is loaded.
Oh good call. I was mentally going at it like it was an action sequence command, but it's a notetag that gets loaded at boot.

However looking at that problem gave me another idea. <Custom Execution> notetags from the skills core should get evaluated before any action sequence takes place, right?
I think that's a good idea to try.

Original thread: https://forums.rpgmakerweb.com/threads/save-item-id-as-variable.151963/