Exploiting 'x_relay's for scriptless timers...
Posted: Sun Oct 28, 2007 1:10 am
While making the editor, I've been 'testing' it's usability by trying to recreate the original DM dungeon. While I'm not hugely worried about accuracy (there's already a DSB DM dungeon available, why make another?), I've been trying to at least get the mechanics working.
From what I've read, the 'x_relay' arch was created so that porting FTL's dungeons through RTSB could be simplified. Because of that, and it's supposed 'limited use in from-scratch DSB dungeons', I've tried to avoid using it as much as possible. But there are a couple of cases when I've found it useful.
Most triggers* in DSB work in a specific way - when they are 'operated', they fire a message at a target (both the message and the target(s) are specified by exvars). How a trigger gets operated is dictated by various exvars (the 'opby's, but 'air' and 'air_only' fall into this group as well), though most deal with something the player does.
'x_relay's are different in that they are operated by messages**, which means they can do some nifty things that triggers normally can't. I've found them useful in two situations in particular.
The first is in sending multiple messages of different types*** (such as different message values or different delays). For example, if you want the player to push a button to activate a teleporter, then want the teleporter to deactivate after a short delay, you can use an 'x_relay'.
When the button is operated, it fires an M_ACTIVATE message to both the x_relay and the teleporter. The 'x_relay' has it's exvars set to fire a M_DEACTIVATE with a delay of 10 at the teleporter. The result is that when the button is pressed, the teleporter activates and the relay is operated, firing it's own message (M_DEACTIVATE) with a 10 tick delay, shutting the teleporter back down.
The second case is if you want to start a message loop; because an 'x_relay' is operated by messages, it can operate itself, setting up a loop. This is useful if you want a continuous operation - such as a door that goes up and down over and over, and the player has to race beneath it.
To set this up, we'd create a door and an 'x_relay', as well as a floor trigger for our "starter". The floor trigger fires an M_ACTIVATE message at the x_relay to initiate the loop. The x_relay is set to fire a M_TOGGLE message at both itself and the door, with a delay of 6. So, when the floor trigger message arrives, it fires those messages - after 6 ticks, the door toggles, and the x_relay is operated again, firing two new messages.
* - Triggers include lots of things in DSB; almost every wall decoration I tested is, in fact, a trigger in disguise. That isn't true with floor decorations, but the invisible floor trigger can be used with anything on top of it.
** - The one message that doesn't work with 'x_relay's is M_DEACTIVATE. This shuts down the x_relay without it operating. Of course, if it's in a messaging loop, it'll recieve an M_TOGGLE message later and reactivate.
*** - This can be duplicated with two triggers being operated at the same time, such as two floor triggers on the same tile or two buttons overlapping on a wall. I don't like this method, because it's harder to see what's going on by just looking at it in the editor (you'd have to select the tile to see it has two buttons or triggers), but it's useful if you need to fire a M_DEACTIVATE message first, since that would normally shut an 'x_relay' down. If you do it this way, be sure to silence one of the triggers (if they make a noise), since two will cause a wierd "echo".
I should note that I'm unsure how stable the message looping is; that is, I don't know what would happen if you had lots of these going on, and the message queue gets over-crowded. I know there are certain archtypes that use looping (like monster generators), but I'm unclear of the actual mechanics of how DSB decides to pay attention to them (do generators work on levels the player is not located?).
Obviously, the best way to accomplish this sort of thing is with scripting, but as I was trying to avoid that, I thought I'd point these out. (I did say the editor could recreate the original DM dungeon without scripting, after all, and I know some people are going to try to do just that sort of thing).
From what I've read, the 'x_relay' arch was created so that porting FTL's dungeons through RTSB could be simplified. Because of that, and it's supposed 'limited use in from-scratch DSB dungeons', I've tried to avoid using it as much as possible. But there are a couple of cases when I've found it useful.
Most triggers* in DSB work in a specific way - when they are 'operated', they fire a message at a target (both the message and the target(s) are specified by exvars). How a trigger gets operated is dictated by various exvars (the 'opby's, but 'air' and 'air_only' fall into this group as well), though most deal with something the player does.
'x_relay's are different in that they are operated by messages**, which means they can do some nifty things that triggers normally can't. I've found them useful in two situations in particular.
The first is in sending multiple messages of different types*** (such as different message values or different delays). For example, if you want the player to push a button to activate a teleporter, then want the teleporter to deactivate after a short delay, you can use an 'x_relay'.
When the button is operated, it fires an M_ACTIVATE message to both the x_relay and the teleporter. The 'x_relay' has it's exvars set to fire a M_DEACTIVATE with a delay of 10 at the teleporter. The result is that when the button is pressed, the teleporter activates and the relay is operated, firing it's own message (M_DEACTIVATE) with a 10 tick delay, shutting the teleporter back down.
The second case is if you want to start a message loop; because an 'x_relay' is operated by messages, it can operate itself, setting up a loop. This is useful if you want a continuous operation - such as a door that goes up and down over and over, and the player has to race beneath it.
To set this up, we'd create a door and an 'x_relay', as well as a floor trigger for our "starter". The floor trigger fires an M_ACTIVATE message at the x_relay to initiate the loop. The x_relay is set to fire a M_TOGGLE message at both itself and the door, with a delay of 6. So, when the floor trigger message arrives, it fires those messages - after 6 ticks, the door toggles, and the x_relay is operated again, firing two new messages.
* - Triggers include lots of things in DSB; almost every wall decoration I tested is, in fact, a trigger in disguise. That isn't true with floor decorations, but the invisible floor trigger can be used with anything on top of it.
** - The one message that doesn't work with 'x_relay's is M_DEACTIVATE. This shuts down the x_relay without it operating. Of course, if it's in a messaging loop, it'll recieve an M_TOGGLE message later and reactivate.
*** - This can be duplicated with two triggers being operated at the same time, such as two floor triggers on the same tile or two buttons overlapping on a wall. I don't like this method, because it's harder to see what's going on by just looking at it in the editor (you'd have to select the tile to see it has two buttons or triggers), but it's useful if you need to fire a M_DEACTIVATE message first, since that would normally shut an 'x_relay' down. If you do it this way, be sure to silence one of the triggers (if they make a noise), since two will cause a wierd "echo".
I should note that I'm unsure how stable the message looping is; that is, I don't know what would happen if you had lots of these going on, and the message queue gets over-crowded. I know there are certain archtypes that use looping (like monster generators), but I'm unclear of the actual mechanics of how DSB decides to pay attention to them (do generators work on levels the player is not located?).
Obviously, the best way to accomplish this sort of thing is with scripting, but as I was trying to avoid that, I thought I'd point these out. (I did say the editor could recreate the original DM dungeon without scripting, after all, and I know some people are going to try to do just that sort of thing).