Yanfly's Damage Core help...

Discussion in 'Javascript/Plugin Support' started by NinjaKittyProductions, Dec 7, 2018.

  1. NinjaKittyProductions

    NinjaKittyProductions Professional Murder Hobos Veteran

    Messages:
    220
    Likes Received:
    149
    First Language:
    English
    Primarily Uses:
    RMMV
    Hey gamers,
    I am currently working on a project and am using yanfly's damage core. I have a damage formula notetag that works for what I need it to do except it looks really ugly and since I am still new to programming, I am having a hard time condensing it down. Any help in making this code more condensed would be greatly appreciated ^_^
    <damage formula>
    if (b.def <= (Math.randomInt(20) + 1 + a.atk))
    {
    If(a.level < 4)
    {
    value = Math.randomInt(6) + 1;
    }
    if (a.level >= 4 && a.level <8)
    {
    value = Math.randomInt(6) + Math.randomInt(6) + 2;
    }
    if (a.level >= 8)
    {
    value = Math.randomInt(6) + Math.randomInt(6) + Math.randomInt(6) + 3;
    }
    }
    </damage formula>
     
    #1
  2. Fornoreason1000

    Fornoreason1000 Black Sheep Veteran

    Messages:
    199
    Likes Received:
    92
    Location:
    Anor Londo
    First Language:
    English
    Primarily Uses:
    RMMV
    Give this a go.
    Im assuming Yanfly is using Eval here, so any javascript should work

    Code:
    <damage formula>
    if (b.def <= (Math.randomInt(20) + 1 + a.atk)) {
        var c  = 0;
        while (c < a.level && c < 9) {
            value += Math.randomInt(6) + 1
            c += 4;
        }
    }
    </damage formula>

    Notice how I've indented some lines each time i go deeper in a condition/iterator and where ive put my curly braces "{" and "}"?

    makes code look alot better. I used a while loop, but a for loop would probably have been better.

    Gud Luk :)
     
    #2
  3. NinjaKittyProductions

    NinjaKittyProductions Professional Murder Hobos Veteran

    Messages:
    220
    Likes Received:
    149
    First Language:
    English
    Primarily Uses:
    RMMV
    This worked out perfectly! Thank you very much!
     
    #3

Share This Page