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
911
Reaction score
575
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

besides itch and occasionally here where are people doing game jams at y'all? (plz do not cross reference this with my previous status lol)
Go out all day!
★No work★
Just want to sleep when I get home Zzzzz
just went through 50 issues of Fables, only to left kind of disappointed by it, I guess I have to wait for season 2 of TWAU instead.
Untitled Project.gif

Feel free to subscribe, cuz im gonna release it first there.
https://crashykk.itch.io/crashykk-retro-tileset
and_remember_tomorrow_beside_myself.jpg

The worst part about making custom stuff is, I can't really ask any of you why a second copy of the character randomly appears only when going SW, S, or SE and changing directions. Been bugging me for the last two days. On the plus side, look at the new random map pieces I made while thinking about it.:LZSexcite:

Forum statistics

Threads
110,437
Messages
1,053,284
Members
143,505
Latest member
7MrLucky7
Top