MZ Moving Events

I have reached a place in my plugin development that requires me to manipulate events. However, I must be missing something because I can't do something as simple as move an event on the map.


Example: I have a character (NPC) on the map as event 1.

I can go into $dataMap.events[1] and set the event's x to x + 1, but the event doesn't move.

Additionally I tried the same in $gameMap._events[1], but still doesn't move.

What am I missing?
I have reached a place in my plugin development that requires me to manipulate events. However, I must be missing something because I can't do something as simple as move an event on the map.


Example: I have a character (NPC) on the map as event 1.

I can go into $dataMap.events[1] and set the event's x to x + 1, but the event doesn't move.

Additionally I tried the same in $gameMap_events[1], but still doesn't move.

What am I missing?
You're missing a period/dot in between $gameMap and _events[1] but I would recommend using this instead of directly accessing the "_events" array use the function "event" of the $gameMap object like this..
Code:
$gameMap.event(1)._x = $gameMap.event(1)._x + 1

Does that do what you need?
$gameMap.event(1).x = $gameMap.event(1).x + 1
That doesn't appear to work. The event refuses to update it's x position.

Here is me attempting to change it multiple times in console.

1652569490676.png


I would have expected it to have an incremental response e.g. 2,3,4,5
sorry I edited my above post.. but you were too quick lol
it's actually "._x" not just .x

if you want it to "snap" to the next x spot instead of moving to it
you can use this:
Code:
$gameMap.event(1)._realX = $gameMap.event(1)._realX + 1
$gameMap.event(1)._x = $gameMap.event(1)._realX

You can also use "setPosition"
so like this:
JavaScript:
$gameMap.event(1).setPosition($gameMap.event(1)._x+1,$gameMap.event(1)._y)
Thanks, that does move it, but it is a slow scroll (like when you set the player to go to a specific location on the map he walks there instead of a teleport.). Anyway to make the position change instantaneous?
Thanks, that does move it, but it is a slow scroll (like when you set the player to go to a specific location on the map he walks there instead of a teleport.). Anyway to make the position change instantaneous?
Lol you're too quick for my edits.
I edited to show how above


if you want it to "snap" to the next x spot instead of moving to it
you can use this:
Code:
$gameMap.event(1)._realX = $gameMap.event(1)._realX + 1
$gameMap.event(1)._x = $gameMap.event(1)._realX

You can also use "setPosition"
so like this:
JavaScript:
$gameMap.event(1).setPosition($gameMap.event(1)._x+1,$gameMap.event(1)._y)
Amazing! That is exactly what I needed. Now I should be able to create my event manager
Amazing! That is exactly what I needed. Now I should be able to create my event manager
Awesome! Glad I could help ☺️

Happy Plugin Making! :LZSgrin:

Original thread: https://forums.rpgmakerweb.com/threads/moving-events.147599/