Indinera

Indie Dev
Veteran
Joined
Mar 13, 2012
Messages
2,003
Reaction score
852
First Language
French
I have this formula:

b.hpRate() < 0.4 ? 3*(a.atk-b.def) : a.atk-b.def;

I would like to know if it's possible to have a switch ON if the 1st condition is met, and OFF otherwise.
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
994
Reaction score
581
First Language
Poland
Primarily Uses
RMMV
b.hpRate() < 0.4 ? $gameSwitches.setValue(id, true); 3*(a.atk-b.def) : $gameSwitches.setValue(id, false); a.atk-b.def;

With ternary statements you can nest things as many as you wish, but remember to put in last position actuall damage formula.
 
Last edited:

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
913
Reaction score
576
First Language
English
Primarily Uses
RMMV
You should never apply effects like this in the damage formula. While it might appear to work correctly in your testing, it can cause an issue when this skill is usable by an enemy, or by an actor who happens to be controlled by AI (via confusion, auto-battle, etc).

That issue is that when the engine is trying to decide which action an AI controlled battler takes, it evaluates the damage formula for every possible skill it could use, and then executes the one with the greatest effect. That works fine normally, but with your example skill above, when it goes to check if this skill should be used, it will turn on your switch regardless of whether this skill ends up being used or not. You might not ever see this happen if the skill can only be used by actors, and the actors can never auto-battle, or otherwise have effects that could cause them to need to evaluate their skill damage in this way, but it's still an avenue in which unexpected behavior could come up if you end up adding in something later.

If you're using the VS plugins, I'd recommend using a <JS Pre-Damage> tag on the skill to set the switch if the hprate() is valid instead, which will only happen when the skill is actually used (and if it actually hits too). If you're not using VS plugins, you could use a common event instead. That might not be as good as checking right when the damage formula is applied, but it might be better to work around it than to have what you currently do in the damage formula.
 

Indinera

Indie Dev
Veteran
Joined
Mar 13, 2012
Messages
2,003
Reaction score
852
First Language
French
If you're using the VS plugins, I'd recommend using a <JS Pre-Damage> tag on the skill to set the switch if the hprate() is valid instead, which will only happen when the skill is actually used (and if it actually hits too). If you're not using VS plugins, you could use a common event instead. That might not be as good as checking right when the damage formula is applied, but it might be better to work around it than to have what you currently do in the damage formula.

How do I type that?
Also, what if instead of setting a switch ON, I want to add a state to the spellcaster?

EDIT:
Never mind, I tried this and it worked.


<JS Pre-Damage>

if (b.hpRate() < 0.5) a.addState(68);

</JS Pre-Damage>

Thanks for your help!
 
Last edited:

Latest Threads

Latest Profile Posts

A good way to practice writing is to write "flash fiction"; very short stories. Link
[CM]
5VaUMjAFpz1I6fSsgDrfJc.jpg

Title is star.
Dam, does the night get to me, I sound and look like a monster. Its 3:54 am right now...I need sleep...or...coffee.
It has nothing to do with my project, but I'm in love with voxels
If you feel like your story isn't that great, just look at final fantasy.

Forum statistics

Threads
110,484
Messages
1,053,634
Members
143,576
Latest member
hsytrggfsdb
Top