MV How to make a returning function for events?

Hi!

Me again doing weird questions 😔

Many times in my game I need to check for any long conditions, I use events for this, something like...

Code:
if(Harold is in the party)
    if(Harold can act)
        if(Harold MP>8)
            if(Harold job is hunter)
                route movement
                through: ON
                speed: 6
                transparent: ON
                Jump: +0 +5
                through: OFF
                speed: 4
                transparent: OFF
            if(Harold job is assassin)
                route movement
                through: ON
                speed: 6
                transparent: ON
                Jump: +0 +5
                through: OFF
                speed: 4
                transparent: OFF
if(Chris is in the party)
    if(Chris can act)
        if(Chris MP>8)
            if(Chris job is hunter)
                route movement
                through: ON
                speed: 6
                transparent: ON
                Jump: +0 +5
                through: OFF
                speed: 4
                transparent: OFF
            if(Chris job is assassin)
                route movement
                through: ON
                speed: 6
                transparent: ON
                Jump: +0 +5
                through: OFF
                speed: 4
                transparent: OFF

I would like to do something like a function to get a single boolean value like this:

Code:
if(canJump())
    route movement
   through: ON
   speed: 6
   transparent: ON
   Jump: +0 +5
   through: OFF
   speed: 4
   transparent: OFF

Where "canJump()" is a function to eval everything and return a single true/false.

How can I do something like this?
You can condense all your nested if statements into a single if statement with a bunch of && between conditions. As for the stuff you want to happen, you either need to put it in a common event and call the commone event, or in a function in a plugin file and call the function.
thank you, I know I can do it that way, but I would really like to know how to do it, my main goal is to reduce the code.

I REALLY want to avoid doing this:

Code:
if((Harold is in the party && Harold can act && Harold MP>8 && (Harold job is hunter || Harold job is assassin)) || (Chris is in the party && Chris can act && Chris MP>8 && (Chris job is hunter || Chris job is assassin)){
    ...
}

😅

you either need to put it in a common event or in a function in a plugin file and call the function.
How can I do this?
Something like this? I'm not sure if I'm properly understanding what you are asking for.

JavaScript:
// the function that would go in a plugin file
Game_Party.prototype.canJump = function(actor) {
    if ($gameParty.members().includes(actor) && actor.canMove() && actor.mp > 8) {
        return true;
    }
}

Check via code:
JavaScript:
if ($gameParty.canJump($gameActors.actor(1)) {
    console.log(actor.name() + ' can jump')
}

Or check via conditional branch:

RPGMZ_K2hvWQwWfa.png

nw_iNhXzw55m7.png



Edit: missed that you are using MV. This might work, but if not, the approach would be pretty similar.
Yes!

it works as expected.

Thank you so much!
Just for completeness:

a non-script version would be to store any input into variables, then call a common event and have the common event store the results into different variables to be checked afterwards.

but it depends on what exactly you want to check to decide which way is the more effective one - event commands are bad when they have to check multiple actors.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-returning-function-for-events.159818/