MV Change Direction

Hello again,

I'm having trouble getting an event to change direction. For example, I want event 1 to turn to face upwards. I tried this, but it didn't work.
JavaScript:
$gameMap.event(1).setDirection(8);

So then I tried this:
JavaScript:
var turnRoute = {
    list: [{code: 19, indent: null}, {code: 0}],
    repeat: false,
    skippable: false,
    wait: true
}
$gameMap.event(1).forceMoveRoute(turnRoute);

That works, but only if put the script into the event editor. If I have the same script in my actual .js file, it doesn't work.
Why are you doing this in js rather than an event? Where you put that code is important, and I suspect that's the problem, but you haven't given us that information. Do you get any error messages in the console? (F8 when doing a play test, then find the Console tab)
I apologize for my poorly framed question. Here's what I'm trying to do.

Imagine you have a party of five characters on a map. I want to be able to move each character one-at-a-time and independently of the other characters. Once each character is done moving, the player can select End Turn on the menu and it will switch over to the next character. Once you switch, the old character should stay where you left him and facing the same direction you left him (which is what I'm struggling with).

1. To start, I have five events lined up on a map, all facing up.
1616092342803.png


2. The character the far right goes first. I set a self switch to hide the event, then add an actor to the party that looks the same. Let's say I move him one space forward and one space right.
1616093103032.png


3. I bring up my custom menu and select End Turn. This switches to the next character and should leave the old character where I left him. I do this by teleporting the event to where the game actor was and trying to get him to turn the same direction as the game actor. I got the teleport to work, but the event won't turn. It's still facing up.🙁
1616093423425.png


Here's my code. When I select End Turn on the menu, it runs a function called moveEventToPlayer().
JavaScript:
// note that $unit is an object representing the event I'm working with

var turnRoute = {
    list: [{code: 19, indent: null}, {code: 0}],
    repeat: false,
    skippable: false,
    wait: true
}

// If self switch A is true, the event is hidden.  If false, the event is visible.
$myKey = [$unit._mapId, $unit._eventId, "A"];

moveEventToPlayer = function() {
    turnRoute.list[0].code = $gamePlayer.direction()/2 + 15;   
    $gameMap.event($unit._eventId).forceMoveRoute(turnRoute);
    $gameMap.event($unit._eventId).locate($gamePlayer._x, $gamePlayer._y);
    $gameSelfSwitches.setValue($myKey, false);
}
When you toggle an event's self-switch, the event checks its page conditions. When an event changes page, many of its properties, including direction, reset to the values defined for that page (cf Game_Event#setupPageSettings). This means you should turn on the event's self-switch, then change its direction. Alternatively, if you just want to toggle the event's visibility, you could use something like:
JavaScript:
$gameMap.event($unit._eventId).setTransparent(true)
This is equivalent to the Transparent ON move route command.

Also, to set location and direction, you may want to use Game_CharacterBase#copyPosition instead:
JavaScript:
$gameMap.event($unit._eventId).copyPosition($gamePlayer);
This will ignore direction fix; otherwise, if your event may be direction-fixed, you will need to temporarily turn off direction fix (setDirectionFix(false)) for setDirection to apply, then turn it back on again if appropriate.

The main reason for constructing a route via script would be for delayed or prolonged movement. Move route commands also parse to setDirection calls, so a move route does not seem appropriate here.
Imagine you have a party of five characters on a map. I want to be able to move each character one-at-a-time and independently of the other characters. Once each character is done moving, the player can select End Turn on the menu and it will switch over to the next character. Once you switch, the old character should stay where you left him and facing the same direction you left him (which is what I'm struggling with).
Out of curiosity, are you trying to make a kind of "Tactical RPG" more simplified?

Edited:
What if you use the graphics in this way?

JavaScript:
$gameActors.actor(Party ID).setCharacterImage('Sprite', Sprite Charset/Sprite Direction)
$gamePlayer.refresh()

Example:
JavaScript:
$gameActors.actor(Party ID).setCharacterImage('Actor1_Splited', 1)
$gamePlayer.refresh()
When you toggle an event's self-switch, the event checks its page conditions. When an event changes page, many of its properties, including direction, reset to the values defined for that page (cf Game_Event#setupPageSettings). This means you should turn on the event's self-switch, then change its direction. Alternatively, if you just want to toggle the event's visibility, you could use something like:
JavaScript:
$gameMap.event($unit._eventId).setTransparent(true)
This is equivalent to the Transparent ON move route command.

Also, to set location and direction, you may want to use Game_CharacterBase#copyPosition instead:
JavaScript:
$gameMap.event($unit._eventId).copyPosition($gamePlayer);
This will ignore direction fix; otherwise, if your event may be direction-fixed, you will need to temporarily turn off direction fix (setDirectionFix(false)) for setDirection to apply, then turn it back on again if appropriate.

The main reason for constructing a route via script would be for delayed or prolonged movement. Move route commands also parse to setDirection calls, so a move route does not seem appropriate here.
Cathryil, you're amazing! Your suggestion worked perfectly. In addition to setting transparency I also added a line to set "through" so you could move through the space where the event was located. Thanks!
Code:
$gameMap.event($unit._eventId).setThrough(true);

Original thread: https://forums.rpgmakerweb.com/threads/change-direction.134488/