by Merk » Wed Jan 20, 2010 9:18 pm
That's a pretty common thing to need to do, and I'm aware of two different ways. I'm not sure I've ever used "react_before" though. You can add any before { } or after { } block to any object for handling specific verbs, such as &DoGo.
Way #1:
In the room where the player can't go west, change this:
w_to newroom
to this:
Code: Select all
w_to {
if (your_condition_goes_here) {
"You can't go that way."
!Alternately, you could customize cant_go.
return false
} else {
return newroom
}
}
Way #2:
In your "player" object, add this:
Code: Select all
before {
actor DoGo {
if (location = whatever) and \
(object = w_obj) and \
(your_condition_goes_here) {
"You can't go that way."
} else {
return false; !Default handling.
}
}
}
I've done both ways. The downside to #1 is that it doesn't lend itself to automatic room exit listing, because if you attempted to get the value of the various room exit properties, you'd end up executing the code inside the w_to block. The downside to #2 is that you have to specific what room and direction *inside* the player object, and if you do this quite a bit, you'll have lots of code that would probably be better placed in each room/direction where it belongs.
There may be a third way, but I forget.
I'm a fan of using the MISC property on an object as special flags, rather than creating a bunch of extra variables. And you can use multiple properties (MISC #1, #2, #3, etc, as long as you set defaults on the object for however many you will use). In my WIP, the player is initially stopped from going East, and a message is shown. When that happens, location.misc #1 is set to true. That's checked when attempting to go "east" so if the player was already warned once, it's allowed the second time.
Good luck!
That's a pretty common thing to need to do, and I'm aware of two different ways. I'm not sure I've ever used "react_before" though. You can add any before { } or after { } block to any object for handling specific verbs, such as &DoGo.
Way #1:
In the room where the player can't go west, change this:
w_to newroom
to this:
[code]w_to {
if (your_condition_goes_here) {
"You can't go that way."
!Alternately, you could customize cant_go.
return false
} else {
return newroom
}
}[/code]
Way #2:
In your "player" object, add this:
[code]before {
actor DoGo {
if (location = whatever) and \
(object = w_obj) and \
(your_condition_goes_here) {
"You can't go that way."
} else {
return false; !Default handling.
}
}
}[/code]
I've done both ways. The downside to #1 is that it doesn't lend itself to automatic room exit listing, because if you attempted to get the value of the various room exit properties, you'd end up executing the code inside the w_to block. The downside to #2 is that you have to specific what room and direction *inside* the player object, and if you do this quite a bit, you'll have lots of code that would probably be better placed in each room/direction where it belongs.
There may be a third way, but I forget.
I'm a fan of using the MISC property on an object as special flags, rather than creating a bunch of extra variables. And you can use multiple properties (MISC #1, #2, #3, etc, as long as you set defaults on the object for however many you will use). In my WIP, the player is initially stopped from going East, and a message is shown. When that happens, location.misc #1 is set to true. That's checked when attempting to go "east" so if the player was already warned once, it's allowed the second time.
Good luck!