Tuesday, January 7, 2025

Toggling Region Behavior in Foundry VTT

I'm using Foundry VTT and wanted to create a map with a manhole (could easily be a trapdoor) that leads to another scene. I came across this Reddit discussion and adapted it for my own use.

The underlying map has an open manhole and I have a separate tile on top to act as the cover. I have a region with a Teleport Tile behavior, initially set to disabled. While the Teleport Token Behavior dialog is open, click the Copy Document UUID button in the title bar to copy the UUID of the behavior (not the region itself) and save it for later.

Set up a Script macro (I called it "Toggle Region Behavior Enabled") and use the following script:

const behavior = args[0] && fromUuidSync(args[0]);
if(behavior)
await behavior.update({disabled: !behavior.disabled});

Using args[0] lets you reuse this macro for multiple things.

I have a tile for the manhole cover that I place over the open hole to cover it. In the tile properties (while in Tile Controls, double-click the manhole cover), go to the Triggers tab, change Controlled By to "GM Only" (unless you want your players to be able to do this) and change the When to "Double Click".

Then switch over to the Actions tab and add an action to "Show/Hide", click the button that looks like Stacked Boxes for "this tile" and choose "Toggle" as the State - this will show/hide the tile itself, revealing the open hole. Then add another "Run Macro" action, select the macro you've created, and use your Region Behavior's UUID as the Args.

Now, when you double-click the tile (make sure to switch back to Token Controls or you'll just open the properties again), the tile will hide and activate the region behavior. When you double-click again, it will re-show the tile and deactivate the behavior.

No comments:

Post a Comment