For example, an event (that is not currently trying to move) is next to a wall or another event, and would therefore not be able to move in that direction, is there a way to check for that with a script call?
MV Script call to check if an event can/cannot move in a certain direction
Learning JavascriptI needed to split it up into multiple lines. The most important function is $gameMap.isPassable(x, y, dir)
Code:
let event = $gameMap.event(EVENT_ID)
let x = event.x // add or subtract 1 to get tile next to this event
let y = event.y // add or subtract 1 to get tile next to this event
let dir = event.reverseDir(event.direction())
let isPassable = $gameMap.isValid(x, y) && $gameMap.isPassable(x, y, dir)
This is a correct answer - just to point it out, you didn't "need" to split it up into multiple lines 😉 It's just less confusing to read.
Code:
$gameMap.isValid($gameMap.event(EVENT_ID).x, $gameMap.event(EVENT_ID).y) && $gameMap.isPassable($gameMap.event(EVENT_ID).x, $gameMap.event(EVENT_ID).y, $gameMap.event(EVENT_ID).reverseDir($gameMap.event(EVENT_ID).direction()))
Replacing, of course, all instances of EVENT_ID with the ID of the event being referenced, then adding or subtracting from x or y to look in the appropriate direction.
OK, thanks a lot. I think I understand this. So really I'm just looking at the tiles around the event and checking whether or not they are passable. I'm not able to play around with this right now, so I'd like to keep this open for the time being. Thanks!
EDIT: OK, I guess I don't understand it. @Aerosys am I supposed to put all those lines into one line separated by commas? I tried using this (to check on event #12 facing down) in the conditional branch script field:
and got the error message "let is disallowed as a lexically bound name, so I changed each "let" to "zet" and got the "Unexpected Identifier" error.
EDIT: OK, I guess I don't understand it. @Aerosys am I supposed to put all those lines into one line separated by commas? I tried using this (to check on event #12 facing down) in the conditional branch script field:
Code:
let event = $gameMap.event(12), let x = event.x, let y = event.y - 1, let dir = event.reverseDir(event.direction()), let isPassable = $gameMap.isValid(x, y) && $gameMap.isPassable(x, y, dir)
and got the error message "let is disallowed as a lexically bound name, so I changed each "let" to "zet" and got the "Unexpected Identifier" error.
👋 Use semi-colons (
Instead, I suggest trying this in Conditional Branch > Script:
This checks if map event ID 12 can move straight forward from where it is, obeying all normal rules: tile passability, character collision, through, etc.
If you want to check a specific direction, you can replace
;) as line separators, not commas (,).Instead, I suggest trying this in Conditional Branch > Script:
JavaScript:
var ev = $gameMap.event(12); ev.canPass(ev.x, ev.y, ev.direction())
If you want to check a specific direction, you can replace
ev.direction() with a number:2= down4= left6= right8= up
JavaScript:
var ev = $gameMap.event(12); ev.canPass(ev.x, ev.y, 4)
Sorry haven't seen your ping @HankB
Caethyril found a better method than I did, you should follow his/her post.
Caethyril found a better method than I did, you should follow his/her post.
Original thread: https://forums.rpgmakerweb.com/threads/script-call-to-check-if-an-event-can-cannot-move-in-a-certain-direction.136692/