Although I'm really comfortable with Javascript I've been having issues figuring out how it actually hooks into the RPG Maker MV system. Is there a way that I can use Javascript to assign an events map coordinates to a variable so I can check them against something? I want to trigger a switch when an event is on a specific tile.
MV Javascript to assign event x/y position to a variable?
RPG Maker MV SupportHello @bomblord!
Well, does it have to be javascript?
You can do it with the normal event command:
Control variable -> Game Data -> Character
In case you absolutely need the javascript:
$gameVariables.setValue(variableId,$gameMap.event(your_event_id).x)
$gameVariables.setValue(variableId,$gameMap.event(your_event_id).y)
Will work.
Edit: Unneccesary complicated answer below kept just in case it might interest you.
If you want a comprehensive list of javascript equivalents to event commands look in this thread:
Hope I helped!
Well, does it have to be javascript?
You can do it with the normal event command:
Control variable -> Game Data -> Character
In case you absolutely need the javascript:
$gameVariables.setValue(variableId,$gameMap.event(your_event_id).x)
$gameVariables.setValue(variableId,$gameMap.event(your_event_id).y)
Will work.
Edit: Unneccesary complicated answer below kept just in case it might interest you.
$gameVariables.setValue(id,$gameMap.events()[0].x)
Will set variable id to the x coordinate of the first event id in your current map.
Or you can use:
$gameMap._events[your_event_id].x
But then you have to be sure your_event_id exists or it will crash the game. The events() function filters the unused event ids out from the actual _events array which has undefined elements in the unused ids.
Will set variable id to the x coordinate of the first event id in your current map.
Or you can use:
$gameMap._events[your_event_id].x
But then you have to be sure your_event_id exists or it will crash the game. The events() function filters the unused event ids out from the actual _events array which has undefined elements in the unused ids.
If you want a comprehensive list of javascript equivalents to event commands look in this thread:
Hope I helped!
Didn't know you could do that in MV that's actually an easier solution than what I was looking for thanks!
Glad to have helped ^^
I have edited my answer because I overlooked an easier javascript way to do it.
Anyway, before resorting to javascript be sure to explore completely the program next time! There are definitely things only possible with javascript, but a surprising amount can be done by exploring the program a bit.
Happy making!
I have edited my answer because I overlooked an easier javascript way to do it.
Anyway, before resorting to javascript be sure to explore completely the program next time! There are definitely things only possible with javascript, but a surprising amount can be done by exploring the program a bit.
Happy making!
$gameMap._events[11].x
$gameMap._events[11].y
Hey one more quick question I've decided to try and use javascript just so I can get used to the implementation.
I have an event set on a custom movement route and I'm using the above to get the x and y of the event. For some reason it wasn't triggering when I thought it should have so I decided to throw the values into a message window to see what I was doing wrong and it's listing the values as the same (13,3) despite the event being moved. Is there something I am doing wrong here?
I've triple verified the event ID is 11 but despite that it keeps spitting out the same value as if the event has not moved
Here's the javascript I'm using to spit out the value (I have it set on a parallel event so it is looping)
$gameMap._events[11].y
Hey one more quick question I've decided to try and use javascript just so I can get used to the implementation.
I have an event set on a custom movement route and I'm using the above to get the x and y of the event. For some reason it wasn't triggering when I thought it should have so I decided to throw the values into a message window to see what I was doing wrong and it's listing the values as the same (13,3) despite the event being moved. Is there something I am doing wrong here?
I've triple verified the event ID is 11 but despite that it keeps spitting out the same value as if the event has not moved
Here's the javascript I'm using to spit out the value (I have it set on a parallel event so it is looping)
Code:
$gameMessage.setBackground(1)
$gameMessage.setPositionType(1)
$gameMessage.add(String($gameMap._events[011].x))
$gameMessage.add(String($gameMap._events[011].y))
Remove the zero. It should be '11', not '011'. The function is attempting to grab the location of an entirely different event.
just as explanation: in some programming languages, leading zeroes are the indicator for numbers in the octal system instead of the decimal system. And 011 octal is 9 decimal...
Ok soooo one more teensy question I'm not seeing in the script call list. How do I use this to get the position of the player?
edit: nvm found it is $gamePlayer.x amd $gamePlayer.y
edit: nvm found it is $gamePlayer.x amd $gamePlayer.y
Original thread: https://forums.rpgmakerweb.com/threads/mv-javascript-to-assign-event-x-y-position-to-a-variable.69026/