Automatically Unlocking Rooms

Note
Since writing this tutorial I have learned of a better way to automatically unlock rooms which does not require an extra item. This better solution can be found at Automatically unlocking rooms (revisited). This tutorial is kept intact mostly for historical purposes and to show that there is often an easier solution to one's problems.

There is an area on Furcadia called FurN that is home to very particular kinds of dreams that need very particular kinds of DS. One of the things that most dreams in FurN have in common is that they have a set of lockable rooms for private 'conversations'. These lockable areas however pose a great risk to the dream owner, since they may stay locked even after all the furres inside have left (some furres even take pleasure in locking all rooms in a dream just to spite the owner).

Over time various methods appeared to make the rooms unlock again. A room-check is one method used, where a staff-member of the dream briefly pops into each of the rooms, checking whether there are furres inside and, if not, unlocking the door. A second method is to automatically unlock the rooms after a certain time, usually combined with a message to anyone in the room so that they can relock the room.

All of these methods have one thing in common though. They interrupt whatever goes on in the room. In the first case you get an unwanted visitor (however briefly). In the second case you're forced to get up and hit the switch again to lock the room. Either way it disrupts the flow of conversation. I felt it could be done better.

This section details some DS that automatically unlocks the room within at most 20 seconds of the last furre leaving the room, regardless of how the furre left the room. This is done in three parts. The first part explains how to lock the room. The second part deals with how we detect the presence of furres in the room. Finally, in the third part, we combine the two into automatically unlocking room DS.

Locking the room

We'll do the easiest part first, which is locking the room. For this we'll use a few of the standard Furcadia items:

161162542543

When the room is unlocked the switch is green (161) and the door is black (543). When the room is locked the switch is red (162) and the door is red as well (542). When a furre bumps into the switch we want to toggle between a locked room and an unlocked room. Furthermore, we want furres to be able to move in and out of the room, but only if it is unlocked.

This leads to the following blocks of dragonspeak:

* lock/unlock the room
(0:7) When somebody moves into position (14,21),
(3:2) at position (14,21) on the map,
(5:6) swap object types 161 and 162.
(3:2) at position (20,21) on the map,
(5:6) swap object types 542 and 543.
(3:2) at position (18,19) on the map,
(5:6) swap object types 542 and 543.

* teleport a furre from the hallway to the room (if the door is unlocked)
(0:7) When somebody moves into position (18,20),
(1:1013) and position (14,21) is object type 161,
(5:15) move the triggering furre to (16,18), or to someplace nearby if it's occupied.

* teleport a furre from the room to the hallway (if the door is unlocked)
(0:7) When somebody moves into position (18,19),
(1:1013) and position (14,21) is object type 161,
(5:15) move the triggering furre to (20,21), or to someplace nearby if it's occupied.

Furre detection

Now we need a way to determine conclusively whether there's a furre present in the room or not. In the past I experimented with counting the furres that moved into and left the rooms. This worked well enough except when furres were summoned into the room. This turned out to be near-undetectable and forced me to turn on the summon-shield in the dream. It just didn't work comfortably.

Fortunately DEP added some interesting DS lines in the squirrel update: idle triggers. Now we have the means to detect whether a furre is doing something and the means to detect whether a furre is doing nothing. This turns out to be just what we need as we can determine that there is no furre in the room if we can't detect any furres doing anything and any furres doing nothing.

All we need are two DS lines that complimentary, i.e. two ds lines where either one or the other triggers. There are a number of possibilities, but I chose the following two (for a reason I'll explain below):

(0:1) Whenever somebody moves,
(0:71) When a furre stays in the same square for # seconds,

Suppose we set the idle-limit to 10 seconds, then within 10 seconds we'll know whether a furre moved (triggering the first line), whether a furre stayed in the same spot (triggering the second line) or whether there was no furre at all.

In the case of our room, this leads to the following two blocks of DS (or atleast the starts of them):

(0:1) Whenever somebody moves,
(1:81) and the triggering furre is within the diamond (14,9) - (14,21),
* ...movement detected inside the room, so do something

(0:71) When a furre stays in the same square for 10 seconds,
(1:81) and the triggering furre is within the diamond (14,9) - (14,21),
* ...idling furre detected inside the room, so do something
(5:18) move the triggering furre back where they came from.

You're probably wondering why I move the triggering furre back in case he stays in the same square. It turns out that the (0:71) cause doesn't trigger every 10 seconds if a furre stays in the same square for long periods of time. Experimentation has shown that it will trigger 3 times, then wait about a minute or more before triggering again. This would be disastrous to our DS as we won't be able to reliably tell whether there's a furre in the room anymore. Fortunately we can fool the system by moving the furre back to where he is already sitting, thus causing the cycle of 3 to restart, thus making sure that it triggers for certain every 10 seconds.

Putting it together

So let's put the two together to complete our automatically unlocking rooms. The way we'll do this is by adding a third state to the switch. This state will be between red and green and we use the following custom item for it:

2400

When the switch is yellow, it means that the room is still locked, but our DS is considering unlocking it unless it detects a furre in the room soon. Since the room is still locked, bumping into a yellow switch will result in unlocking the room (turning the switch to green and the door to black). Furthermore, every 10 seconds we'll change the red switch to yellow. If we detect movement or idling within the room, we'll change the yellow switch back to red. If another 10 seconds pass and the switch is still yellow, then obviously there were no furres inside the room anymore and the room can be unlocked completely.

Combining the above ideas with the DS for the room-locks and the furre-detection leads to the following complete DS for an automatically unlocking room:

* teleport a furre from the hallway to the room (if the door is unlocked)
(0:7) When somebody moves into position (18,20),
(1:1013) and position (14,21) is object type 161,
(5:15) move the triggering furre to (16,18), or to someplace nearby if it's occupied.

* teleport a furre from the room to the hallway (if the door is unlocked)
(0:7) When somebody moves into position (18,19),
(1:1013) and position (14,21) is object type 161,
(5:15) move the triggering furre to (20,21), or to someplace nearby if it's occupied.

* lock/unlock the room
(0:7) When somebody moves into position (14,21),
(3:2) at position (14,21) on the map,
(5:6) swap object types 161 and 162.
(5:5) change object type 2400 to type 161.
(3:2) at position (20,21) on the map,
(5:6) swap object types 542 and 543.
(3:2) at position (18,19) on the map,
(5:6) swap object types 542 and 543.

* unlock the room if the switch is still orange after 10 seconds
(0:100) When 10 seconds have passed, offset by 0,
(1:1013) and position (14,21) is object type 2400,
(5:41) place object type 161 at (14,21).
(5:41) place object type 543 at (20,21).
(5:41) place object type 543 at (18,19).

* prepare the room for unlocking in 10 seconds
(0:100) When 10 seconds have passed, offset by 0,
(3:2) at position (14,21) on the map,
(5:5) change object type 162 to type 2400.

* movement inside the room -> lock the room fully again
(0:1) Whenever somebody moves,
(1:81) and the triggering furre is within the diamond (14,9) - (14,21),
(3:2) at position (14,21) on the map,
(5:5) change object type 2400 to type 162.

* 'idling' furres inside the room -> lock the room fully again
* in addition, perform a small trick to make sure that the idle trigger keeps triggering every 10 seconds
(0:71) When a furre stays in the same square for 10 seconds,
(1:81) and the triggering furre is within the diamond (14,9) - (14,21),
(3:2) at position (14,21) on the map,
(5:5) change object type 2400 to type 162.
(5:18) move the triggering furre back where they came from.

Conclusion

This method of locking/unlocking the rooms may seem a bit more work than most would want to put into room-DS, but remember: once it's written, you'll never have to worry about locked rooms anymore. To me, that makes these 31 lines of DS seem like a small price to pay.

P.S. A sample dream demonstrating the DS made here is available in the small box at the top.