How to check if multiple events are in multiple different XY coordinates?

Hey everyone, I'm in need of some help with this:

Basically, in my game there's a simmetry puzzle, where 8 different chairs need to be pushed and pulled to match the chairs on the other side of the room.

I've used this tutorial to make a push/pull system that works perfectly fine. My problem is:

I need to check all of these event's coordinates to make sure they're in the right spot, that way, I can add to a variable that counts the amount of objects that are in their correct places.

The thing is, from my knowledge, I would need to make X and Y variables for all 8 events, and check all of their X/Y locations in a parallel event, that will add or subtract to the "CorrectObjects" Variable accordingly.

And that is, obviously, very, very time consumming and, I suppose, not very optimized.

Just to illustrate better what I mean, here's a picture of the chairs scrambled out of place, and in their correct positions:
1740151367586.png

Scrambled chairs

1740151400189.png

chairs in their correct spot

I want to be able to add to a variable if the chairs are in their correct spots, and subtract if they aren't. I have already tried a more local approach where, after the common event for pushing and pulling ends, a conditional branch checks the event's X and Y coordinates, and adds/subtracts to the "CorrectObject" Variable according to that.

However there's two issues with this:
  • If the player is quicky mashing the Z button, they might push or pull the chair out of the correct spot even after the event adds to the CorrectObject Variable. Causing the chair to be in the wrong spot but read as if it weren't.
  • The adding or subtracting only happens when the player is touching/interacting with the chair event.
1740151910675.png

Here's how the event looks at the moment.

So, if anyone knows of a more simple/to the point way of checking these coordinates, I'd love to know! Thank you in advance. 👋
How about using another paralell event to check if all the chairs are in correct position?
Something like this:

correct = 0
x = chair1 x
y = chair1 y
if x and y both are correct
correct += 1
end
.....
x = chair8 x
y = chair8 y
if x and y both are correct
correct += 1
end
if correct = 8
do something
end
If you don't mind using some code, you could do the whole thing in one long if statement using $gameMap.eventsXy(x, y). That command gets an array of every event currently sitting at co-ordinates (x, y). If none of your events are set to "Through" then anything in the right spot will be first in the array, so you can use $gameMap.eventsXy(x, y)[0]._eventId to check it has the right ID. Something like this:

Code:
If: Script: $gameMap.eventsXy(5, 5)[0]._eventId == 2 && $gameMap.eventsXy(5, 6)[0]._eventId == 3 && $gameMap.eventsXy(5, 7)[0]._eventId == 4

Would check to see if event 2 is in spot (5,5) and event 3 is in spot (5,6) and event 4 is in spot (5,7). (Change the event numbers and the coordinates to whatever you need).

If you do have ways to have multiple events in the same spot on your map (like, some of the events have THROUGH enabled), you'll do to do a bit more work, something like:

Code:
$gameMap.eventsXy(5, 9).some(el => el._eventId == 2)

to check if any of the events on spot (5,9) have ID 2.
Do you place the chairs in a scrambled position in the editor or are they in the correct positions in the editor and you run an event that scrambles the chairs for you?

I would put them all in the correct position in the editor, scramble them with an autorun event command/script call at the beginning of the map, and run the script call below.

You can put it with the push/pull common event you have and run it when you are moving the event - no need for parallel check or adding/subtracting variables (unless you are keeping score or something).

The script call below is assuming you are using event IDs 9-15. You can put your event IDs in the array instead:
JavaScript:
const arr = [9, 10, 11, 12, 13, 14, 15],
        d = $dataMap.events,
        e = $gameMap._events;
if (arr.every(a => e[a].pos(d[a].x, d[a].y))) {
  $gameMessage.add('YOU DID IT!');
}

Edit: if you are starting them in the editor already scrambled, you can still compare them to the other events and add a constant to the X coordinate to check (let's assume the event ids of the correct chairs on the left are 1-7 and are grouped to be 1 is the same as 9, 2 is the same as 10, etc.):
JavaScript:
const arr1 = [1, 2, 3, 4, 5, 6, 7],
      arr2 = [9, 10, 11, 12, 13, 14, 15],
         e = $gameMap._events;
if (arr2.every((elem, i) => e[elem].pos(e[arr1[i]].x + 6, e[arr1[i]].y))) {
  $gameMessage.add('YOU DUN DID IT!');
}
If you don't mind using some code, you could do the whole thing in one long if statement using $gameMap.eventsXy(x, y). That command gets an array of every event currently sitting at co-ordinates (x, y). If none of your events are set to "Through" then anything in the right spot will be first in the array, so you can use $gameMap.eventsXy(x, y)[0]._eventId to check it has the right ID. Something like this:

Code:
If: Script: $gameMap.eventsXy(5, 5)[0]._eventId == 2 && $gameMap.eventsXy(5, 6)[0]._eventId == 3 && $gameMap.eventsXy(5, 7)[0]._eventId == 4

Would check to see if event 2 is in spot (5,5) and event 3 is in spot (5,6) and event 4 is in spot (5,7). (Change the event numbers and the coordinates to whatever you need).

If you do have ways to have multiple events in the same spot on your map (like, some of the events have THROUGH enabled), you'll do to do a bit more work, something like:

Code:
$gameMap.eventsXy(5, 9).some(el => el._eventId == 2)

to check if any of the events on spot (5,9) have ID 2.
Thank you so much for this! This is exactly what I needed! A condensed, even if long, script to check all of the event's locations. 😂

Not only did it help me check for the events locations, but the alternative code in case two events where in the spot, also came in handy for making a second puzzle, where the player needs to push a chair into a door to make it appear in another other room. Together with Yanfly's save event location, this puzzle's basically done! 😤

1740233121288.png


Thank you, also, to everyone who took the time to reply! The mods may close this thread if needed.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-check-if-multiple-events-are-in-multiple-different-xy-coordinates.175700/