RMMV How to access a item's js variable created in Yanfly's Item Core

Thornton

Villager
Member
Joined
Jul 17, 2015
Messages
7
Reaction score
1
First Language
English
Primarily Uses
RMMV
Hey everyone,
I'm using Yanfly's Item Core plugin alongside ICFSoft's Param Core (Link).

What I'm trying to do is access a js variable that was assigned by a independent item during the "<On Creation Eval>" tag so that my custom stat can increase in value based on the generated number.
What I have is:
JavaScript:
<On Creation Eval>
    var strBonus = Math.floor(Math.random()*5)+5;
</On Creation Eval>

And whenever I paste the following code right underneath that tag,
JavaScript:
<CUSTOM NPARAMS>
str = strBonus;
</CUSTOM NPARAMS>
Nothing happens. My knowledge of JS isn't that wide yet to know how to access such information.

This is all within the same item, and not trying to access it from skills and whatnot.
I'm not sure if it's possible, but it's worth to see if it is.
 

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
913
Reaction score
576
First Language
English
Primarily Uses
RMMV
Instead of using var, which is a local scope declaration, assign the variable to the item object itself, so it can be called back from anywhere that has access to the item.

Code:
<On Creation Eval>
    item.strBonus = Math.floor(Math.random()*5)+5;
</On Creation Eval>

I'm not sure if there are any shortcuts in the ICFSoft plugin to get the variable from that item again easily like this.strBonus, or item.strBonus, since I don't use it. I'm sure the help documentation for that plugin can be of help there, though.
 

Thornton

Villager
Member
Joined
Jul 17, 2015
Messages
7
Reaction score
1
First Language
English
Primarily Uses
RMMV
@ramza
Wow, that was surprisingly easy and fast, thank you! It was fairly critical to get this to work.

Yeah, if it comes down to that I'll try to analyze the documentation again.

Thread is solved!
 

Latest Threads

Latest Posts

Latest Profile Posts

Progress on one of my projects has been slow, but I'm at a spot now where I feel like sharing the four main characters.

From left to right we have: Amabel, Tibby, Dusty, and Wren.

tibbyrpgcast.jpg
I'm in a much better mood about my game than I was 2-3 days ago. I keep switching between sideview and front because of the amount of assets needed for side (I'm drawing it all myself)... but I've decided to stick with front, for my own sanity. sidenote... people, planning is important. I've spent so long on just getting my game's ideas off the ground because I didn't plan ahead.
unknown.png

"Fight me."
I'll finally wash my clothes today!
SA46ATTACK.gif :kaojoy:New Arab character in action.

Forum statistics

Threads
110,610
Messages
1,054,689
Members
143,736
Latest member
wildsky
Top