MV Javascript help to check if any event is at player X, Y in a conditional branch

Hello everyone, I'm trying to check in a common event if any event of the current map is at the same coordinates of the player. The code should work for every event of the map, checking each one, and it should work in every map. It's on a common event.

Tried this, but doesn't work.

Code:
for (let i = 1; i <= $gameMap.events().length; i++) {
  if ($gameMap.event(i) {
      let PlayerX = $game_player.x
      let PlayerY = $game_player.y
      let eventX = $gameMap.event($gameMap.event(i)).x;
      let eventY = $gameMap.event($gameMap.event(i)).y;
      if (Math.abs(PlayerX-eventX) = 0 && Math.abs(PlayerY-eventY) = 0) {
          $gameSwitches.setValue[1] == true;
      }
  }
}

Then I check if switch [1] is true. Any help?
You can use event commands for this, no scripting required:
  • Control Variables -> Game Data -> Character -> Map X|Y
  • Get Location Info -> Designation with variables
E.g.

◆Control Variables:#0001 PlayerX = Map X of Player ◆Control Variables:#0002 PlayerY = Map Y of Player ◆Get Location Info:Variable 3, Event ID, ({PlayerX},{PlayerY}) ◆Text:None, Window, Bottom : :Event ID at player position is \v[3].
This value will be equal to the lowest ID of all events on that tile, or 0 if there are no events there.
no need for script or complex code, this can be done by a simple sequence of event commands, doesn't even need a loop:

control variable X= Player X
control variable Y=Player Y
get location info: variable 3, player X/Y, "Event ID"
conditional branch Variable 3 = 0?


If the variable storing the result of get location info has a zero, then the player position has no event.
otherwise it returns the ID of the event on that position

EDIT: ninja'd
Thank you for help but I guess that won't work if I don't know how many events are in the map. They can be 0 or they can be 1 for each tile.

ID = 0, 1, 2, 3, ....n (all tiles)

Edit:

Worked! Smart way to solve the problem!
but I guess that won't work if I don't know how many events
wrong, our method will always give a valid event ID if there is one event on the tile, no matter how many events you have on the map
wrong, our method will always give a valid event ID if there is one event on the tile, no matter how many events you have on the map
It works! Thank you both. What about if I'd like to make it as a script, as a Javascript exercise? What if I want to check for each event if coordinates are true each at once?
It works! Thank you both. What about if I'd like to make it as a script, as a Javascript exercise? What if I want to check for each event if coordinates are true each at once?
$gameSwitches.setValue(1, $gameMap.events().some(event => event.x === $gamePlayer.x && event.y === $gamePlayer.y))

Original thread: https://forums.rpgmakerweb.com/threads/javascript-help-to-check-if-any-event-is-at-player-x-y-in-a-conditional-branch.154163/