Is it possible to store an event’s x, y into variables from a specific map, without the player having to be in said map? Or maybe reference the event’s x,y directly from a specific map using a script call?
Question about storing X,Y of an event
RPG Maker MV SupportIt is. I dont know the command by heart, but all you need to do is do read that map.json data and look into the events.
Use the "script" option in the Control Variable event command and store this:
or
If you want you can even use a single script call and write this:
or you could store both values in a single variable as an array. If you want to know more about this you can take a look at this thread containing MV script calls. There is also an example where an array is stored in a variable (it is more or less the same as storing a single value).
Code:
$gameMap.event(event_id).x
Code:
$gameMap.event(event_id).y
Code:
$gameVariables.setValue(varId, $gameMap.event(event_id).x);
@Heirukichi that only works for the events on the current map ($gameMap), the OP asked specifically about accessing data from events on other maps.
@woop
it is possible, but not by simple script call. Only the current map exists in memory and there is no other space in RAM by default, so you'll need a plugin that temporarily loads that other map into a new map structure, then checks the data of the event and copies it and then releases the memory of the other map again.
You might look into existing "clone event" plugins as they would have to do the same to get the event data to be cloned from another map.
EDIT:
And just as an addendum: since the player is not on that map, the events on the other maps are not processed and cannot move in that time (if your question was made while believing the other maps would work)
@woop
it is possible, but not by simple script call. Only the current map exists in memory and there is no other space in RAM by default, so you'll need a plugin that temporarily loads that other map into a new map structure, then checks the data of the event and copies it and then releases the memory of the other map again.
You might look into existing "clone event" plugins as they would have to do the same to get the event data to be cloned from another map.
EDIT:
And just as an addendum: since the player is not on that map, the events on the other maps are not processed and cannot move in that time (if your question was made while believing the other maps would work)
You're right, I completely missed that part. I guess the only way to do it is to have either the event or the map stored in memory from somewhere else then.
EDIT
However, there is one thing I do not understand about this request...the position of each event is set back to its original position when the map is loaded again. What is the point of storing its X and Y in a variable? Why not using their numeric value taken from the editor then? If the event has been moved and the OP is using a plug-in to store events position, it means the map has been loaded already and you can just store the new event position when the event moves, there is no need for something as heavy as loading a whole map into memory for that.
@woop Well...concerning setting variables equal to the X and Y coordinates of an event from a different map, you could technically do that at the start of the game since you placed every event at a particular X and Y coordinate in the editor and that's its home when not on its map. Then you just reference those coordinate variables when you want to. Bonus: If you want to call an event from another map, Yanfly has a plugin for that: Call Event. Hope it helps. 🙂
That's a really important distinction. If OP is using some plugin to store the event position, then that's a different question entirely than reading from the map json file.
Anyways to the read the x and y for an event on a different map:
Code:
const getRemoteEventXY = async (mapId, eventId, coords) => {
const rawStream = await fetch(`/data/Map${mapId.toString().padStart(3, '0')}.json`)
const json = await rawStream.json()
coords.x = json.events[eventId].x
coords.y = json.events[eventId].y
}
const coords = {}
getRemoteEventXY(10, 5, coords) // populate coords variable with x,y of event 5 on map 10
console.log(coords)
Note this requires MV 1.6+ because doing that in pre-2015 Javascript is tedious. If you're going to do this a bunch, then paste that function to a .js file and then you can just call the function in an event or something.
Thank you for the information, that helps a lot! I didn't realize these clone event plugins existed, I've been using Galv's Event Spawner to call in events from a specific map but there's no support for referencing their x,y, but I think Orange's Custom Event Creator might be able to solve my issue.
I've been making it so that the player can spawn in an event from a specific map to any other map, and have that event interact with other map events.
With the help of all of you guys, I think I've gotten everything to work now, thank you!
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.
Original thread: https://forums.rpgmakerweb.com/threads/question-about-storing-x-y-of-an-event.109172/