Temporary Switch States

In my game I have a scene where the players are running from a guard. If the guard catches them, it triggers a fight. That event is working fine, but I want to set it so that when the battle ends, the guard collapses. I want to set it up so that the guard will stay down until the player leaves the room. Then if they walk back in, the guard will be back up.

I set it up with a self switch onto a second page (with the "damage" form of the guard sprite"). The problem is when I walk back in, the guard has gone back to their original position but is still collapsed and refuses to chase the player (presumably because the self switch is still activated).

Is there a way to reset the self switch when the player leaves the room? Or to accomplish this through some other method? Failing that, is there some way to give the player time to escape after winning the battle, so that the guard doesn't immediately trigger another combat?
$gameSelfSwitches.setValue([mapID, eventID, swtich], true/false);
where switch can be "A", "B", "C", or "D"

use it in event like this (replace values with your own)
Thanks for that.

Presumably that needs to be set on the guard's scripting? How can I set a condition for the player leaving the room to apply it? (I know how to set a conditional branch: but I'm not sure of what code I could use to do this.)

EDIT: Actually, the MAP ID and Event ID is used to locate the self switch, right? So I can add it anywhere, such as the transfer event between rooms? Perfect.
For the second part of question Yes, for first use conditional branch event, select 4th tab with script option and Type in text field

if ($gameSelfSwitches.value([mapid, eventid, switch]))

This mean if self switch on your map with following event is True then do something.

Right now im at work SO i cannot show screenshot of This conditional branch and im on phone

Original thread: https://forums.rpgmakerweb.com/threads/temporary-switch-states.123197/