RPG Maker Forums

Hey guys,

Is there a command to check whether a function has the same value as a list of values, similar to what ''[2, 6, 8].contains(variable)'' does?

I need to know this because i made a function that checks what direction the player wants to walk, and itd save code if i can have multiple values do the same thing.

This is the code that its about

Code:
function DirectionUsed() {
    if (Input.isPressed("left") && Input.isPressed("down")) return 1;
        else if (Input.isPressed("right") && Input.isPressed("down")) return 3;
        else if (Input.isPressed("left") && Input.isPressed("up")) return 7;
        else if (Input.isPressed("right") && Input.isPressed("up")) return 9;
        else if (Input.isPressed("down")) return 2;
        else if (Input.isPressed("left")) return 4
        else if (Input.isPressed("right")) return 6
        else if (Input.isPressed("up")) return 8
        else return 0
}

Game_Player.prototype.moveByInput = function() {

    if (!this.isMoving() && this.canMove() && PCM === true) {

        if (PlayerDirection > 0) {
            $gameTemp.clearDestination();
        } else if ($gameTemp.isDestinationValid()){
            var x = $gameTemp.destinationX();
            var y = $gameTemp.destinationY();
            PlayerDirection = this.findDirectionTo(x, y);
        }

        if ([2, 4, 6, 8].contains(DirectionUsed())) this.executeMove(PlayerDirection);  //!!!contains doesnt work with a function!!!
            else if (DirectionUsed() === 1) this.moveDiagonally(4, 2);
            else if (DirectionUsed() === 3) this.moveDiagonally(6, 2);
            else if (DirectionUsed() === 7) this.moveDiagonally(4, 8);
            else if (DirectionUsed() === 9) this.moveDiagonally(6, 8);

    }
};

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,470
Members
137,821
Latest member
Capterson
Top