RMMV Is there a way to check and count states on a target, without using a million if conditions?

TheTitan99

Veteran
Veteran
Joined
Nov 2, 2015
Messages
217
Reaction score
99
First Language
English
Primarily Uses
RMMV
So, I've made this simple little function:

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.
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
972
Reaction score
566
First Language
Poland
Primarily Uses
RMMV
@TheTitan99
Code:
var positiveStates = []; //put positive states ids
var negativeStates = []; //put negative states ids
for (var i = 0; i <= positiveStates - 1; i++){
    n += 1;
}

for (var i = 0; i <= positiveStates - 1; i++){
    n -= 1;
}

But then, if you want a different values for different states, then

Code:
var positiveStates = []; //put positive states ids
var negativeStates = []; //put negative states ids
for (var i = 0; i <= positiveStates - 1; i++){
    if (b.isStateAffected(positiveStates[i]){
        n += Number($dataStates[positiveStates[i]].meta["buff"]);
    }
}

for (var i = 0; i <= negativeStates - 1; i++){
    if (b.isStateAffected(negativeStates[i]){
        n -= Number($dataStates[positiveStates[i]].meta["debuff"]);
    }
}

and place in your states notetags: https://prnt.sc/xo8lnx

Actually you can stick to the only one notetag, but using two will give you further informations about boosts.
Because of my age I leave that way a hint for myself in case I forgot what function/state etc do
 
Last edited:

TheTitan99

Veteran
Veteran
Joined
Nov 2, 2015
Messages
217
Reaction score
99
First Language
English
Primarily Uses
RMMV
Thank you! There were a few typos in that code, but after fixing those, it works like a charm! Much, much cleaner code.
 

Latest Threads

Latest Profile Posts

The light has gone out of my life.

About time they finally press the kill switch button for older makers.
Sorry everyone, I am here sporadically. After 6 years of delays after delays in my life, I try to do all mat once and that means that I spread thin everywhere because it just is impossible to crunch 6 years in one or even two, but I try! I wish many of that I would already given you and put behind but... well...
I'm looking for an experienced gamer who has played a few games created with RPG Maker, who knows what an alpha build is, who may remember the old days when cliché was the favorite word on Creation Asylum, who, if a reviewer, would ask for my permission before making a review to post on YouTube, or whatever, since I will be messaging you a 10 minute, or so, DEMO based on an alpha build of Effervesce Fallacy™.
No matter how many times I listen to him, I know this is Joker speaking, but my brain can only hear Dagda.

Forum statistics

Threads
108,821
Messages
1,039,805
Members
141,279
Latest member
SawYuuki
Top