Question about storing X,Y of an event

Status
Not open for further replies.

woop

Freelance Illustrator
Veteran
Joined
Apr 13, 2016
Messages
44
Reaction score
85
First Language
English
Primarily Uses
RMMV
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?
 

Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
377
Reaction score
348
First Language
german
Primarily Uses
RMMZ
It 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.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
Use the "script" option in the Control Variable event command and store this:
Code:
$gameMap.event(event_id).x
or
Code:
$gameMap.event(event_id).y
If you want you can even use a single script call and write this:
Code:
$gameVariables.setValue(varId, $gameMap.event(event_id).x);
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).
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,342
Reaction score
7,659
First Language
German
Primarily Uses
RMMV
@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)
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
specifically about accessing data from events on other maps.
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.
 
Last edited:

mathmaster74

just...John
Veteran
Joined
Jun 12, 2016
Messages
285
Reaction score
193
First Language
English
Primarily Uses
RMMV
@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. :smile:
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
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.
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.
 

woop

Freelance Illustrator
Veteran
Joined
Apr 13, 2016
Messages
44
Reaction score
85
First Language
English
Primarily Uses
RMMV
@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)
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.

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.
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!
 
Last edited:

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,829
Reaction score
5,221
First Language
Dutch
Primarily Uses
RMXP

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.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Latest Threads

Latest Profile Posts

Getting work done in the hospital is a little tough :kaosigh:
Yet another custom skill animation, sometimes i waste too much time on details people will barely notice :kaocry:
Time flies by... already 1/6th of the calendar released :o

Forum statistics

Threads
105,822
Messages
1,016,718
Members
137,520
Latest member
KM_Dub
Top