MV Problem with RPGMaker MV JS Code

Hello, I'm trying to make a script for an event where it will jump on tile forwards within the confines of region 1:
var px = $gamePlayer.x; var py = $gamePlayer.y;
var ev = $gameMap.event(this._eventId);
var dx = 0, dy = 0;
switch ($gamePlayer.direction()) {
case 2: dy = 1; break; // player facing down
case 4: dx = -1; break; // player facing left
case 6: dx = 1; break; // player facing right
case 8: dy = -1; break; // player facing up}

if ($gameMap.regionId(ev.x + dx, ev.y + dy) !== 1) {ev.jump(dx, dy);}

However, RPGMaker doesn't seem to work for (ev.x + dx, ev.y + dy). How can I fix this?
1756252935305.png

This is my console output :
Update: I fixed it.

Working code if anyone's interested -


var ev = $gameMap.event(this._eventId);

var dx = 0, dy = 0;

switch ($gamePlayer.direction()) {
case 2: dy = 1; break;
case 4: dx = -1; break;
case 6: dx = 1; break;
case 8: dy = -1; break;
}

if ($gameMap.regionId(ev.x + dx, ev.y + dy) == 1) {
ev.jump(dx, dy);
}
Yep, the closing } for the switch statement got caught in the comment:
JavaScript:
case 8: dy = -1; break; // player facing up}
Moving the } to the next line, like you've done, fixes it.
It often helps to write even tiny code snippets into something like Microsoft Visual Studio Code because it tells you syntax errors quickly.
It often helps to write even tiny code snippets into something like Microsoft Visual Studio Code because it tells you syntax errors quickly.
That sounds good- I'll try that next time ^_^

Yep, the closing } for the switch statement got caught in the comment:
JavaScript:
case 8: dy = -1; break; // player facing up}
Moving the } to the next line, like you've done, fixes it.
Thank you - it took me a while to realise that haha

Original thread: https://forums.rpgmakerweb.com/threads/problem-with-rpgmaker-mv-js-code.179802/