Get Location Info Priority

Hi.

I have a scenario where two events can exist at the same location (not by default/initially) and I'm trying to use Get Location Info to identify the ID of the second event that is placed at this location.

However, I have discovered Get Location Info prioritises the "earlier" event. In other words, if the first event has ID number X and the second event has ID number X+Y, Get Location Info (Event ID) always gives the event ID of the first event because X is less than X+Y.

Is there a method to prioritise the "older" event (higher numbered ID)?
OR is there a way to assign an ID number to an event? Because if I can assign a high number to the first event, such that any other event's ID number would always be lower, I should be able to work with that.
You need a scriptcall for that.
PHP:
// Returns all events at a certain x,y position
var events = $gameMap.eventsXy(x, y);

// If there is a second event. (First event would be events[0])
if (events[1]) {
   // Get the second events eventId
   var eventId = events[1].eventId();
   
   // Store it in a game variable
   $gameVariables.setValue(5, eventId);
}
@waynee95 that you very much. I can work with this.
EDIT: Uh, nevermind. Now it doesn't work as I expect it to. Don't understand how I observed that irregularity before.

Hmm, something's happening that I don't fully understand @waynee95 . This is the script code I've created inside a conditional if branch command:

Code:
$gameMap.eventsXy($gameMap.event(this._eventId).x,$gameMap.event(this._eventId).y)[0] &&
$gameMap.eventsXy($gameMap.event(this._eventId).x,$gameMap.event(this._eventId).y)[0].eventId()
!== this._eventId

The event ID this branch is in is 211. The events I've used to place it at it's location have IDs 192 and 212.
The script code works for both events, but I thought it would not work for ID #212 since that data should be in [1] not [0] (therefore the script code above should be 211 == 211 and it should fail).

The logic you presented to me works though. I implemented it another way in a separate parallel event and it can differentiate between [0] and [1] as I understand it.

@ Moderators; I reported the thread to be closed, but can I postpone that request?
Are you saying "this" event is on a certain spot, and you want to see if there is another event on the same spot and get that event's id? Try putting this in the Script slot of a Control Variables:

Code:
var me = $gameMap.event(this._eventId); var them = $gameMap.eventsXy(me.x, me.y).filter(function(evt) { return evt.eventId() != this._eventId; }.bind(this)); them ? them[0].eventId() : 0;

If the variable is 0, it means there's no other event on the same spot. If it's not 0, it's the id of the other event. If there are more than 2 events on that spot, it will return only one id.

I don't have MV with me so I haven't been able to test this. It may give errors.

I wouldn't write any code that relies on events being returned from a function in a certain order.
@Shaz
Are you saying "this" event is on a certain spot, and you want to see if there is another event on the same spot and get that event's id?
Yes, that's right.

I've been successful with what I want to do. Using the logic I learned above, I check events[0] and events[1]. Both [0] and [1] could never have the same event ID, so if more than 1 event exists at this specific spot, one is bound to have a different ID than the original event ID at that spot. As long as I detect at least one event with a different ID than the original, the condition is true.
So, does this mean that you want your Report request to close this carried out, or do you want to leave it open a while longer?
@Kes I think it can be closed now. I hope a problem doesn't arise. Sorry for any trouble.
@Rink27 No trouble at all. Much better to keep it open when you discover an issue than to have to start a new one.

Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/get-location-info-priority.86236/