Better to use gameVarable or obj._x ??

Dear all,

Since I'm not as good as I should with JavaScript, I don't know which of the two following "code" is the best.
What I want to do is to bind a variable to an item. This variable is then use to increase a specific stat with attachable augments.
Here the plugins I'm using :
  • YEP_X_AttachAugments
  • YEP_ItemCore
Spoiler: concrete example
Consider the following items :
  • an augment that increase ATK.
  • a sword weapon
  • a cane weapon
Since the sword is made for an attack base actor and the cane for a magic based actor, it is (to me) a non sens that the augment can give the same ATK increase for both sword and cane. Thus, I expect that the increase the augment provides to sword is greater than the increase it provides to cane.

To do so, I don't know which one of the two following procedure is the best :
  • creating a variable when the item is created using the <On Creation Eval> notetag and using item._augmentIncrease = x
  • storing the variable in gameVariable using the <Info Eval> notetag and using $gameVariables.setValue(i, x)
Spoiler: Concrete using <On Creation Eval>
weapon notetags :

<On Creation Eval>
item._atkIncrease = 10
</On Creation Eval>

augment notetags :

<Augment Attach Eval: Glyph>
item.params[2] += item._atkIncrease
<Augment Attach Eval: Glyph>

Spoiler: Concrete using <Info Eval>
weapon notetags:

<Info Eval>
$gameVariables.setValue(1, 10) // atk
<Info Eval>

augment notetags :

<Augment Attach Eval: Glyph>
item.params[2] += $gameVariables.value(1)
<Augment Attach Eval: Glyph>

for sure, I've tested both methods and both work. I'm just wondering if one of those two methods is better, considering that many items can be created along the game.

Thanks,

Lay.
If it's something that you want to only set once and have available for the rest of the game, even if the player closes the game then resumes later, you should put it as a $gameVariable, as that will be included in the save file.

If you want to set it then use it straight away, and you don't care about it after that (or if you will set it again every time you want to use it), then a variable is fine.

But what is item in "item._augmentIncrease"? Is it $dataItems[x]? Or is item also a temporary variable? If it's $dataItems[x] then I wouldn't use that at all, because if you change $dataItems[x] and the player goes back to the title screen then starts a new game, that variable will be set on that item. And if you set it then close the game and resume later, then it won't be set because $dataItems gets reloaded and anything you've done to it is forgotten. $data<stuff> gets loaded when the game is first launched. $game<stuff> gets created when you select New Game, and loaded when you select Continue, so it's refreshed with each new game and stays for the duration of the game.
@Shaz

Thanks for your clear explanation. It's exactly the kind of answer I was expecting and I'm now fixed 🙂.

Since I need those variables to persist through successive game sessions, I will go for a $gameVariable setup.

Many thanks,

Lay.
Actually, I wan't paying close attention to which plugins you're using. If the augment plugin already has the ability to record these things, my guess is that it would persist throughout the game. If that's the case it's probably better to record it there than to use an additional variable.

It wouldn't take much to test it out - do the augment increase, confirm it's been updated, save, exit the game. Resume and confirm it's still set.
yep, I've tested it and the variable of interest is not reloaded from saves. Thus, I can't use augments on a weapon that were created during previous game session. Need to make use of $gameVariable instead.

Thanks,

Lay.
I would have thought that would be a part of that plugin? Once augmented, always augmented, unless you change it.

Maybe you should get some help from people more familiar with the plugin, or have them confirm the change doesn't stick.


Edit - I notice the instructions for the Augment plugin state it needs to go under the ItemCore plugin, but in your post, you've listed the Augment plugin first. Do you have them in the correct order in your plugin list? ItemCore above Augments?

I've moved this thread to Javascript/Plugin Support. Thank you.

@Shaz

Yes sory for listing my plugins badly. This was a mistake and all are well ordered in my plugin list.

I will explain a bit with more detail how I'm using the plugins here.

YEP_ItemCore allow to make weapon and armor as independent items. Thus, two items with same itemID can be custom independently (what's mandatory to use an augment in the game, you don't want to modify all the item with same ID when using an augment on one of them).

YEP_ItemCore provide the ability to eval code when an item is created. This code located in the <On Creation Eval> notetag allows the dev to modify the item parameters using item.params[2] = 10 // set the atk to 10. This is useful if you want to alter the item parameters and introduce per example a notion of parameter fluctuation (the way yanfly provide param fluctuation in its plugin is not satisfying to me).
The modified stat are well carried over save/load even when game is closed in between.

In prevision to the augment system. I also used <On Creation Eval> to set variable that will be used to compute the augment value. The idea is to have augment value specific to each independent item. Thus the notetags looks like as below

Code:
<On Creation Eval> // WEAPON NOTETAG
item._atkIncrease = 10
<On Creation Eval>

Code:
<Augment Attach Eval: Glyph> // AUGMENT NOTETAG
item.params[2] += item._atkIncrease
<Augment Attach Eval: Glyph>

with the previous notetags, I expect that using the augment on weapon increase the atk by +10.

If a do the item creation and augment procedure in a row, everything is fine. the weapon atk is increase by 10 and the new params seems to be well stored in save files.
If a do the item creation, close the game, re-open it, load the save and then do the augment procedure. The atk of the weapon is not correct. Meaning that I can't use item._atkIncrease = 10 for it since this variable is not carried over save files.

But I didn't know that before my post. You've just taught me that 🙂
Best,

Lay.

Original thread: https://forums.rpgmakerweb.com/threads/better-to-use-gamevarable-or-obj-_x.120581/