MV Need help using Javascript in Yanfly Item Synthesis

Hello all,

I have been trying make a simple function happen when crafting a weapon which apparently is not as simple for me (noob to Javascript).

Basically I'm trying to make it so when a weapon is crafted depending on the attack parameter of the weapon it adds the Grade of the weapon to the description and changes the color of the text. Initially I though I had done something wrong with the color but I just can't get anything to work.

Here is the last snipped I tried

For those asking for link to plugin:

In the link is the custom code snipped as an example


<Custom Synthesis Effect>

var weaponId = 1;

var WeaponAtk = weapon.params[2];

if (WeaponAtk < 40) {

var description = " *Junk Grade";

$gameSystem.setItemDescription(weaponId, description);

}

</Custom Synthesis Effect>

Thanks for y'all help 🙂
When you're putting code in a post, you should use the CODE tags (the </> in the edit bar). That will preserve indentation and brackets.

var WeaponAtk = weapon.params[2];
What is weapon? That variable isn't provided to you by the Item Synthesis instructions, and you don't declare it previously.


$gameSystem.setItemDescription(weaponId, description);
Where the heck did you get this from? This doesn't exist.

If it were real, it's doing fundamentally the wrong thing, as you don't want to change the description for database item 1, you want to change it for this item.

Did this attempt come from AI?
weaponAtk isn't defined either, and if it's a custom code, it's surely isn't
default code as the code base wont save the database items and description.

and it also might need the independent items as changing 1 ID without it
changes it for each item of that ID.

even if it gets saved and only get once in the game, it doesn't matter that
much by than, but no link to the plugin or custom code is missing as well.
I have just been collecting snippets I have found online and using what I think would work. I do not know how to make it work. I also didn't know the var had to be provided by yanfly, I also though "var" declared it. Thanks for the info. I would still like some guidance into how to get close to it working.
I have just been collecting snippets I have found online and using what I think would work.
generally speaking, just finding stuff and putting them together wont do much good if you dont understand what they do and why theyre needed

I also didn't know the var had to be provided by yanfly, I also though "var" declared it.
you declared a variable called "weaponAtk", but since its value depends on a property of "weapon" and "weapon" doesnt exist, weaponAtk wouldnt have a value

I would still like some guidance into how to get close to it working.
it looks like the item synth notetag youre using has "item" refer to the direct database item, not the independent item being created. I know the item Core's <On Creation Eval> does refer to the specific item though. you should be able to use this
Code:
<On Creation Eval>
if (item.params[2] < 40)
item.description = "*Junk Grade";
</On Creation Eval>
and it should work fine, but that will apply to the weapon any time the player gets a copy of it. not just from synthesis
generally speaking, just finding stuff and putting them together wont do much good if you dont understand what they do and why theyre needed


you declared a variable called "weaponAtk", but since its value depends on a property of "weapon" and "weapon" doesnt exist, weaponAtk wouldnt have a value


it looks like the item synth notetag youre using has "item" refer to the direct database item, not the independent item being created. I know the item Core's <On Creation Eval> does refer to the specific item though. you should be able to use this
Code:
<On Creation Eval>
if (item.params[2] < 40)
item.description = "*Junk Grade";
</On Creation Eval>
and it should work fine, but that will apply to the weapon any time the player gets a copy of it. not just from synthesis
Thank you for the insight, I have little understanding but just don't know how the system interacts fully. The value of WeaponAtk I though it would just grab it from the atk param, I though putting a [2] in there would use it since it's the number assigned to atk as far as I understand.

I tried to use <On Creation Eval> Initially but though that was the reason nothing was working.

I'll try that snippet and then mess around with getting it working on just synthesis. Thank you so much for the help, I really appreciate it.

edit: want to add that snipped you provided makes so much more sense, I feel like I was kinda on the right tracks, just very derailed lol

Original thread: https://forums.rpgmakerweb.com/threads/need-help-using-javascript-in-yanfly-item-synthesis.170055/