check if function is multiple values?

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);

    }
};
Are you sure? The DirectionUsed function ought to evaluate and return the appropriate value before contains runs. The function in question seems to be missing semicolons at the end of the last few lines (return 4, 6, 8, and 0)...maybe that's the source of the problem? =)

If not, the first thing I'd try is using some console.log('test'); kind of messages to see exactly where the code is, and isn't, going.
[2,4,6,8].includes(DirectionUsed())
Array.prototype.contains is defined in rpg_core.js, it ought to work. 😅
Does it give you any errors when you look at the console?

Where is PlayerDirection defined/set? It's possible that .contains is working correctly, but executeMove is not.

Could there be issues because you don't end each line/statement with ; in the DirectionUsed function?

Is that the correct way to define a function? I'm only familiar with MV's use of Javascript, and it defines a function as
DirectionUsed = function() {
...
}
@caethyril @Shaz Wooops, ''[2, 4, 6, 8].contains(DirectionUsed()'' was working perfectly fine apparently... the problem was with that the code still had some remains of a variable that i used before i tried using a function - And that botched everything. Also "includes" did cause an error, and doesnt seem to work. this is the working code, in case youre interested:

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 (DirectionUsed() > 0) {
            $gameTemp.clearDestination();
        } else if ($gameTemp.isDestinationValid()){
            var x = $gameTemp.destinationX();
            var y = $gameTemp.destinationY();
            DirectionUsed() = this.findDirectionTo(x, y);
        }
        if ([2, 4, 6, 8].contains(DirectionUsed())) this.executeMove(DirectionUsed());
            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);

    }
};

And thanks to you both for your input! For some reason, I hadnt even thought of that the problem mightve been somewhere else instead of [].contains().
you should use contain instead of include.

contain are very performance friendly
This it the polyfill
PHP:
ƒ (element) {
            return this.indexOf(element) >= 0;
        }

and include are very bad performance, take a look on this huge polyfill.
Use only in some context.
PHP:
// https://tc39.github.io/ecma262/#sec-array.prototype.includes
if (!Array.prototype.includes) {
  Object.defineProperty(Array.prototype, 'includes', {
    value: function(searchElement, fromIndex) {

      if (this == null) {
        throw new TypeError('"this" is null or not defined');
      }

      // 1. Let O be ? ToObject(this value).
      var o = Object(this);

      // 2. Let len be ? ToLength(? Get(O, "length")).
      var len = o.length >>> 0;

      // 3. If len is 0, return false.
      if (len === 0) {
        return false;
      }

      // 4. Let n be ? ToInteger(fromIndex).
      //    (If fromIndex is undefined, this step produces the value 0.)
      var n = fromIndex | 0;

      // 5. If n ≥ 0, then
      //  a. Let k be n.
      // 6. Else n < 0,
      //  a. Let k be len + n.
      //  b. If k < 0, let k be 0.
      var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);

      function sameValueZero(x, y) {
        return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
      }

      // 7. Repeat, while k < len
      while (k < len) {
        // a. Let elementK be the result of ? Get(O, ! ToString(k)).
        // b. If SameValueZero(searchElement, elementK) is true, return true.
        if (sameValueZero(o[k], searchElement)) {
          return true;
        }
        // c. Increase k by 1.
        k++;
      }

      // 8. Return false
      return false;
    }
  });
}

Original thread: https://forums.rpgmakerweb.com/threads/check-if-function-is-multiple-values.95731/