MV script call for movement route based on actor state?

Hi, I'd appreciate any advice. I thought I could use a script call to make events (roaming enemies) move toward the player unless a certain actor had a certain state, in which case the event would move away from the player. When I look at the script call list I see moveType = 0 for fixed, 1 for random, and 2 for approach, with no option for move away even though there is a movement command "Move away from Player." Could 3 possibly be move away?

A separate issue is I am quite ignorant about script calls so my sad attempt at putting this as the custom movement route failed:
if $gameActors.actor(1).isStateAffected(50) {$gameMap.event(8)._moveType = 0} else {$gameMap.event(8)._moveType = 2}

This gives "Unexpected Identifier."

Thanks to anyone who can point me in the right direction!
= is "is". "is equal to" is ==
Edit: Sorry, I'm still sleeping. You're missing brackets surrounding your if condition.
Thanks so much, Poryg! No more error messages! So if I set moveType to 0 (fixed) if state is ON and 2 (approach) if state is OFF then my enemy (as intended) either stands still or moves towards the player. But when I change the state it's not noticing the change and reevaluating the conditions until I transition off map and back on. If that is what it is, fine.

However, when I experimentally put moveType to 3 if state is ON and 2 if OFF, then something different happens. The event stands still when the state is ON, the same as moveType 0. But as soon as I flip a switch to turn OFF the state, the enemy begins moving towards me, as if it is now a parallel process? But turning it ON has no effect until I leave the map and come back.

Looks like this:
if ($gameActors.actor(1).isStateAffected(50)) {$gameMap.event(8)._moveType = 3} else {$gameMap.event(8)._moveType = 2}


Thanks for any further insight or information!
But when I change the state it's not noticing the change and reevaluating the conditions until I transition off map and back on. If that is what it is, fine.

I think we can fix this part. Try putting this line after the state is changed:
Code:
$gameMap.requestRefresh()
Thank you, but I must be doing something wrong as it's not having an effect. 🙁 Is this what you meant?
Spoiler
xXHsMrS.png
(Sorry, please bear with me as I attempt to figure out how to include images properly...)
Moved to: Learning JavaScript
Perhaps you can find the help you need with that last part here.
Hope it's okay to bump this.

I'm still not having success. 🙁 I have three questions/issues. 1. $gameMap.refresh() doesn't have an effect, the event still approaches until I leave the map and return, whereupon the event stands still . 2. To copy this formula for each event do I need the event's ID or can I use "this" -- if so, I haven't been successful figuring out the syntax. 3. I see in the script call list there is "Game_Character.ROUTE_MOVE_AWAY = 11;" Would that be useful and if so, how to implement? Sorry for my cluelessness. ^_^;

Original thread: https://forums.rpgmakerweb.com/threads/mv-script-call-for-movement-route-based-on-actor-state.111750/