- Joined
- Nov 2, 2015
- Messages
- 217
- Reaction score
- 99
- First Language
- English
- Primarily Uses
- RMMV
So, I've made this simple little function:
Basically, bad states lower the returned number, and good states raise the number. This is useful for, say, enemy AIs, as they can now check to see if they should dispel targets. You don't wanna dispel a poisoned ally if it has a million positive states on it after all!
The only thing is, this code feels super bad. It works, but I feel there's gotta be a better way to do this than a mountain of if conditions! Like, there's gotta be simple loops or something, right?
I think this is the right board for this question.
Code:
//Check conditions.
//Returns a value. The higher the number, the more positive status effects are n it. Lower means more negative effects.
Titan_CheckConditions = function(b) {
var n = 0;
//Positive states
if(b.isStateAffected(42))
n = n + 1;
if(b.isStateAffected(43))
n = n + 2;
if(b.isStateAffected(44))
n = n + 1;
if(b.isStateAffected(45))
n = n + 2;
//Negative stats
if(b.isStateAffected(52))
n = n - 1;
if(b.isStateAffected(53))
n = n - 2;
if(b.isStateAffected(54))
n = n - 1;
if(b.isStateAffected(55))
n = n - 2;
//Positive conditions
if(b.isStateAffected(62))
n = n + 1;
if(b.isStateAffected(63))
n = n + 1;
if(b.isStateAffected(72))
n = n + 1;
if(b.isStateAffected(73))
n = n + 2;
//Negative conditions
if(b.isStateAffected(82))
n = n - 1;
if(b.isStateAffected(83))
n = n - 1;
if(b.isStateAffected(91))
n = n - 1;
if(b.isStateAffected(94))
n = n - 3;
if(b.isStateAffected(95))
n = n - 2;
return n;
}
Basically, bad states lower the returned number, and good states raise the number. This is useful for, say, enemy AIs, as they can now check to see if they should dispel targets. You don't wanna dispel a poisoned ally if it has a million positive states on it after all!
The only thing is, this code feels super bad. It works, but I feel there's gotta be a better way to do this than a mountain of if conditions! Like, there's gotta be simple loops or something, right?
I think this is the right board for this question.