Damage formula with variable

● ARCHIVED · READ-ONLY
Started by Bersjerker 7 posts View original ↗
  1. Hi there,

    I'm trying to test some new formulas to spice up the skills but I really don't know yet how to do this one :

    if (v[1] > 100) { a.atk*4 - b.def*2 } else { a.atk*2 - b.def*2 }

    Basically, I want to make a variable that deals a lot more damage if it reach 100 with variable 1, but I'm really stuck on how to do it. Can you please explain to me how exactly I must proceed ?
  2. This would be much easier (at least for me)
    Code:
    v[1] <= 100 ? 10 : 500

    In short, engine checks value of your variable and by result of statement returns one of two options. In my example
    if variable ID 1 is lower or equal 100 then skill will deal 10 point damage. In other case damage will be set to 500.
  3. Unless you're using a plugin, I believe you'll want to use the ternary operator, as @Landazar says, because the alternative syntax using if/else statements is much longer and more confusing. A simple overview of how it works:
    {condition} ? {'true' value} : {'false' value}
    so if {condition} is true, it returns the {true value}, else it returns the {false value}. Now, there's a couple tricks you can do here, because the ternary operator is technically treated like +, -, *, or any other math operator:

    You can use it in math: (v[1] > 100 ? a.atk*4 : a.atk*2) - b.def*2 (make sure you use parens to make your order of operations clear)
    You can nest it: v[1] < 100 ? 5 : v[1] < 200 ? 50 : 500 (in this case, your {false value} contains another ternary operator, so it works like an if () else if () else () chain)

    The important thing to remember about the formula bar is whatever code you put in needs to boil down to a number, according to standard javascript rules.
  4. Woaw thanks okay didn't know all of that ! For now it's all clear, but does the variable works ? Do I put it as a common event ? It's my first time so I'm sorry for my noobiness
  5. To set variable in game. Create an event and in event tab (first page) choose Control Variables. You can do it via common event or event on a map, you choose. @Doktor_Q , thanks. I didn't know I can nest conditions like that.
  6. Ok I got it ! I finally understand the way common events work with variables! Thank you a lot guys
  7. Yes, now you have to run this event