Exit dungeon item with common event

I'm having some trouble with an item using a common event attached to allow the player to escape to the overworld from certain areas. I have the event set up and functional, but what I'd like to see happen is to receive a message that says "You can't do that here" if the player is not currently in one of the affected maps. I can't seem to make it function as intended.

Here is a screenshot of the event that works for all desired areas:
Project1 - RPG Maker MV 6_27_2025 9_45_15 PM.png


The event is set up the same for all desired maps (currently there are 4). Then when I add the "you can't do that here" message in the "Else" branch to ONE (and only one) of the maps, it works properly only for that map. Here is the screenshot reflecting this:
Project1 - RPG Maker MV 6_27_2025 9_47_21 PM.png


So in this example, when in map 14 it works correctly. But when in any of the other three affected maps, I still get the message that says "You can't do that here". And if I add the message to all the affected maps, none of them work and regardless of the current map I still get the "you can't do that here" message. I am rather confused at why it is doing what it is doing.

Any advice or suggestions are greatly appreciated.

Thanks,
Chew
I think it would be best to, instead of checking if map ID = 14 or any other number, check if a switch is turned on.

If the switch "can escape to overworld" is on, then do the teleport, if not, display the message that you can't do that here.
You get that message because it is always checking if map 14, then if not show that message. So on the other maps it will not be map 14 and it will play that message.

A better way would be to tie it to a switch. Put a parallel process on every map and in that have it turn ON the switch when you can use it, and turn it OFF when you cannot. Then put erase event after that switch command.

That parallel will run once when you start up the map and load a save, set the switch and vanish until you reenter the map.

Also you can later put other things like this in that parallel, if needed.
if you use different maps Id's, you want them inside the else handler.


if mapId = 14
//do stuff
else
if map id = 23
do stuff
else
if map Id = x
do stuff
else
// you cant use it here
end
end
end


alternative, you can make a loop like: [14, 23, 4, 6, 3].forEach($gameMap.mapId())
this snippet is wrong, but you can do it a different way, so you check if any ID is
inside the array else, use the else handler.
You could try using my SFG_SwitchCommand plugin, which offers a way to check a chain of possibilities in a single event command, but in this case I think it might be better to do as others are saying and use a switch. I assume the code in each of the 4 conditionals is the same except for the actual location teleported to, right? If that's case, you can set a switch and 3 variables when you enter the dungeon – one of the variables contains the ID of the overworld map, and the other two contain the X and Y coordinates. Then you can select Designate by Variable in the transfer command and reference those variables, meaning the actual code for escape will be the same for every map.
I find it a lot easier to do some housekeeping each time you change a map. Eg. setting a "you can teleport here" switch, indoor/outdoor switch, etc. Rather than trying to gather information from the game state, you can do all your stuff in one place each and every time, and you don't have to worry about event page priorities, parallel events, and stuff like that.
Or you could go to a completely different way of handling this - your idea would create a really big Common Event if you have more than a few dungeons.

1) in the event that transfers the player into the dungeon, you set three variables to contain the escape position (map id, x, y) for that specific dungeon.

2) in the event that leaves a dungeon, you set all values to zero again.

3) in the common event for the escape item, you check if the stored map id is zero.
if yes report "can't use here", if not teleport to the stored escape values and set all values back to zero as if leaving the dungeon like in 2

That way, you can add as many dungeons as you want without ever bothering to change the item common event.
Or you could go to a completely different way of handling this - your idea would create a really big Common Event if you have more than a few dungeons.

1) in the event that transfers the player into the dungeon, you set three variables to contain the escape position (map id, x, y) for that specific dungeon.

2) in the event that leaves a dungeon, you set all values to zero again.

3) in the common event for the escape item, you check if the stored map id is zero.
if yes report "can't use here", if not teleport to the stored escape values and set all values back to zero as if leaving the dungeon like in 2

That way, you can add as many dungeons as you want without ever bothering to change the item common event.

That's an elegant approach. for myself, though, I tend to reflect they don't charge you by the number of switches used... 🙂
Thanks you all for the replies and suggestions; I really appreciate it!

@ShadowDragon, I think the result I was hoping for matches what you said about putting the next "If" inside of the "Else" branch of the previous condition. I just tried going that route and it all seemed to function as intended. Thank you! I seem to recall doing this to begin with, but was much more of a rookie back then...

@Andar, your solution to not have to change the event when adding more dungeons does seem more sensible if I end up with more than a handful of dungeons. I will have to weigh my options on which way to go for the long haul. I will fiddle with this setup as well, and see what works best for my situation.

Again I thank you all for the feedback. What an amazing community!

Thanks,
Chew

Original thread: https://forums.rpgmakerweb.com/threads/exit-dungeon-item-with-common-event.178639/