A variable known exclusively for an item

Discussion in 'Learning Javascript' started by EGStryker, Jan 13, 2018.

  1. EGStryker

    EGStryker Veteran Veteran

    Likes Received:
    First Language:
    In my game, I implemented a system wherein whenever an equipment is received(through shop, event or enemies), there will be a bunch of codes to run that will include bonus upgrade to some parameters on that weapon. For example, in my database, Dagger only increases atk by 50. But the code I put in whenever the item is created will generate random stat increase in it.

    However, since it's going to be random, it will be wise to display what the random bonuses are to let the players know what else it gives. This is when I stumbled upon a problem, displaying the random bonus.

    I'm using Yanfly's Item Core to create this and this is the piece of code I put in.

    <On Creation Eval>
    var options = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
    this._itembonus = "";

    for (var i=1; i < 4; ++i) {
    var randomizer = Math.floor(Math.random() * 10) + 1;

    if(randomizer = 1 && options[0] <= 0) {
    var bonus = Math.floor(Math.random() * 20) + 10;
    weapon.params[2] = baseWeapon.params[2];
    weapon.params[2] += bonus;
    this._itembonus += " STR + " + bonus;
    options[0] = 1;
    }//end strength

    if(randomizer = 2 && options[1] <= 0) {
    var bonus = Math.floor(Math.random() * 20) + 10;
    weapon.params[4] = baseWeapon.params[4];
    weapon.params[4] += bonus;
    this._itembonus += " MAG + " + bonus;
    options[1] = 1;
    }//end magic

    if(randomizer = 3 && options[2] <= 0) {
    var bonus = Math.floor(Math.random() * 20) + 10;
    weapon.params[3] = baseWeapon.params[3];
    weapon.params[3] += bonus;
    this._itembonus += " DEF + " + bonus;
    options[2] = 1;
    }//end def

    if(randomizer = 4 && options[3] <= 0) {
    var bonus = Math.floor(Math.random() * 20) + 10;
    weapon.params[5] = baseWeapon.params[5];
    weapon.params[5] += bonus;
    this._itembonus += " MDEF + " + bonus;
    options[3] = 1;
    }//end magic

    }//end for loop
    </On Creation Eval>

    <Info Eval>
    var txtbox = this._itembonus;
    $gameVariables.value[55] = this._itembonus;
    </Info Eval>

    <Info Text Bottom>
    </Info Text Bottom>

    I'm very new in coding and this is what my beginner knowledge have me done. Basically, there will be 10 different types of bonuses (kinda explains the array at the initialization part). The distribution of bonus stat is working as intended, but I can't seem to display the set of strings I'm making into the Info Text Bottom tag. I don't even know if this._itembonus is working, but based on what I've seen and tried from a few yanfly tips & tricks that uses that kind of code, it should be known to other notetags but it isn't. It only display "0" and nothing else. I've tried making the first line in Info Eval like this

    var txtbox = "BONUS: " + this._itembonus;

    But this one gave me "BONUS: undefine"

    I just need to know how to store all the strings I've made inside the On Creation Eval known to the info eval. Storing it in a gameVariable wouldn't do as this will overwrite the string whenever the same kind of item is received. Hoping someone could help me here as this is a vital feature in my game. TIA :D

    EDIT: After hours of trying, I dumped the idea of storing the set of strings from the On Creation Eval notetag to a variable.

    What I have in mind if referencing the highlighted Weapon/Armor in the menu and check its parameters. Is this possible? Been trying to find a way to do this but all I got was getting the parameter it gives based on the game's database.
    Last edited: Jan 13, 2018

Share This Page