Help using Variables in Damage Formula first atk returns Zero??

Discussion in 'RPG Maker MV' started by Nerdboy, Feb 5, 2017.

    Tags:
  1. Nerdboy

    Nerdboy Veteran Veteran

    Messages:
    78
    Likes Received:
    7
    Hi i tried this in a new project nothing loaded just to test if plugins were causing it but no its not same problem.

    What's happening is when i use a variable in damage formula like a.atk * v[id] - b.def * v[id]; the first attack always returns zero, for some odd reason is this a bug? first attack works when no variable is used, but when a variable is added, it always returns zero on first hit, subsequent ones work though...

    does anyone know what is causing this first attack returns zero damage?

    I watched some youtube videos on variables in dmg formula and they seem to work on first use tho, i have the latest update too. what's causing this in new project even with nothing loaded?
     
    Last edited: Feb 5, 2017
    #1
  2. Nerdboy

    Nerdboy Veteran Veteran

    Messages:
    78
    Likes Received:
    7
    so i do think this is a bug but here is a workaround.

    b.isStateAffected(id) ? a.atk - b.def : a.atk * v[id] - b.def * v[id];

    put in all troop events turn 0 entire troop state change to a default state that does nothing but give it a state that last one turn.

    what happens here is it inflicts base damage on first turn, then afterwards when first turn is up, defaults to variable damage rate. odd bug but atleast your not doing zero damage on first attack.
     
    #2
  3. shockra

    shockra Slightly Crazy Programmer Veteran

    Messages:
    394
    Likes Received:
    166
    Location:
    US
    First Language:
    English
    Primarily Uses:
    RMMV
    Maybe the math is off somewhere. What exactly is the variable you're using for? What changes this variable? Because if it starts at 0, you're multiplying by 0, and the result will always be 0 until the variable changes. A little more information may help figure out the problem.
     
    #3
  4. Nerdboy

    Nerdboy Veteran Veteran

    Messages:
    78
    Likes Received:
    7
    *Actually your right, when skill calls a common event, before its used its zero, since common event is called after skill is used, so at game start i have control variable set at random 1-6, then in common event, i have it re-roll control variable 1-6. works like a charm. without having to use states.

    true, but i still think its a bug because the following code still returns zero.

    a.atk * (v[id] + 1) - b.def * (v[id] +1);

    or

    a.atk * (1 * (v[id] + 1)) - b.def * ( 1* (v[id] +1));

    still zero.

    the control variable id im using is 28 and 29, their names are x and y, and they randomly generate 1-6 not zero.

    What i'm trying to do is have a dice roll system in my game, where the positive dice rolls are Multipliers to damage and defense. Even if i set control variable to flat number say 1000, and in damage formula just set at v[id] nothing else, it still deals zero damage on first attack subsequent use works though.

    but im not so sure, cuz ive seen youtube videos where they do the same thing like

    control variable = 1000

    damage formula
    v[id]

    and it deals 1000 first turn.

    note - the control variable is set during a common event, that the skill calls.
     
    Last edited: Feb 6, 2017
    #4
  5. shockra

    shockra Slightly Crazy Programmer Veteran

    Messages:
    394
    Likes Received:
    166
    Location:
    US
    First Language:
    English
    Primarily Uses:
    RMMV
    One possible issue is that the dice roll isn't calculated until after the damage, so it may still calculate the variable as zero. Or maybe defense winds up being too high and inflicts no damage.

    Is the variable being manipulated through a common event in the skill? If so, it may be that the event takes place AFTER the damage, so it doesn't take the dice roll into account for that attack. If that's the case, it would explain why it works on later attempts; it's using the dice roll for the PREVIOUS attack.
     
    #5
  6. Nerdboy

    Nerdboy Veteran Veteran

    Messages:
    78
    Likes Received:
    7
    yes, i know, common event from skill triggers after damage formula. so you are right, i just had to initialize control variable = 1-6 at beginning of game, and everything works now.
     
    #6

Share This Page