Formula question

Midnight Kitty

Midnight
Veteran
Joined
Jun 18, 2013
Messages
129
Reaction score
14
First Language
English
Primarily Uses
RMMV
I have a query about the damage formula in RPG maker mv.
Can two if/else statements be used within each other.
Code:
if (a.isActor()) 75 + (a.mat * (v[52] + v[54])) - b.mdf * 2; else 75 + (a.mat * 5) - [new if & else statement] b.mdf * 2;
for example an if statement placed here;
 

Midnight Kitty

Midnight
Veteran
Joined
Jun 18, 2013
Messages
129
Reaction score
14
First Language
English
Primarily Uses
RMMV
I guess I could overpush the limits on how much damage to see if it works.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,087
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
These two lines are equivalent when used in the damage formula box:
Code:
if (a > b) a - b; else a + b
a > b ? a - b : a + b
However, the second line is what to use whenever you want to "if" something mid-line, e.g.
Code:
if (a.isActor()) 75 + a.mat*(v[52] + v[54]) - b.mdf*2; else 75 + (a.mat*5) - (b.def < b.mdf ? b.def : b.mdf) * 2
Remember to put it in brackets so you're sure what's included in the statement and what isn't. ^_^

Another option, depending on what you're trying to do, is to follow your "else" clause with another "if", e.g.
Code:
if (a.isActor()) 10; else if (b.isActor()) 20; else 0
This will do 10 damage if the user is an actor, 20 if the target is an actor but the user isn't (because it's after the first "else"), and 0 otherwise.
 

Midnight Kitty

Midnight
Veteran
Joined
Jun 18, 2013
Messages
129
Reaction score
14
First Language
English
Primarily Uses
RMMV
Thanks that should help with what I want to do.
I wanted to increase def based on if the target is an actor or enemy.
This is the new formula should be able to check if it works later
Code:
if (a.isActor()) 75 + (a.mat * (v[52] + v[54])) - b.mdf * 2; else 75 + (a.mat * 5) - (b.def < b.mdf ? b.def * 2 : b.mdf * 3);
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,087
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
As-is, that's comparing the target's def and mdf stats against one another. If you want to check whether the target is an actor or enemy, you might want something like this instead:
Code:
...stuff goes here... - (b.isActor() ? b.mdf * 4 : b.mdf * 2)
I.e. "if the target is an actor, subtract 4 times their mdf stat, otherwise subtract 2 times their mdf".
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,019
Members
137,564
Latest member
McFinnaPants
Top