I ran across an interesting problem in my WIP that to solve I went through a couple different solutions before getting something simple to work.
Note: This may not be the best way to handle the problem and I’m always open to suggestions for improvements.
In my current WIP (one of them anyway), I have a situation where I had a large object that was visible from many rooms. Let’s say a large tree in my front yard and the rooms are areas around the yard. There is also one room inside my house that I can see the tree out a window. My first inclination was to make it a backdrop so it could be seen from those rooms. Let’s assume that the entire map of the game is those outside locations and that one room in the house.
The shade tree is a backdrop. The shade tree is everywhere. The description of shade tree is "A great big tree."
Worked great, until i wanted to the tree to be a supporter. I tried adding the supporter tag to the tree “The shade tree is a backdrop and a supporter.” This gave me the error: “… as a backdrop and a supporter are incompatible…” I really needed the tree to be a supporter as it was critical to be able to put something on the tree. So out came the backdrop and making the tree a supporter worked great.
However, it wasn’t very realistic. It made no sense that I could go to a different part of the yard and if I tried to look at the tree I would get the message: “You can’t see any such thing.” Well what’s the best way to be able to interact with an object that is not in the current location? Put it in scope.
after deciding the scope of the player: place the tree in scope;
This worked fine, now I could examine the tree from anywhere. And if I tried to do anything to the tree away from the actual location where the tree is, I get a message saying “I can’t reach into Under-the-tree” (which is where the tree is located). Well that’s not a very good message so I need to change the rule for reaching inside a room (which is what you’re doing if you are trying to interact with an object, in scope, that is located in another room.)
Rule for reaching inside a room: if the location is up-the-tree: if the noun is the shade tree: allow access; otherwise: say "You can only look at [the noun] from a distance."; deny access; otherwise: say "You can only look at [the noun] from a distance."; deny access.
Let’s look at a few things with this last section of code.
- We are replacing the rule for reaching inside a room from the standard library so we can run some of our own checks.
- We first check to be in the location up-the-tree. I hadn’t mentioned this before, but I let the player climb the tree and it puts you in a location up-the-tree. Since the tree is not in that room, but is in-scope (because of our scope rule) without this rule we would have gotten the “Can’t reach into” message. Which is silly since of course I can “touch the tree” since I’m in it.
- So if we are in the tree and the noun is the tree (meaning we are trying to do something to the tree while up the tree) then we allow access, which lets the appropriate rules and actions trigger.
- The otherwise’s tell us we are either not up the tree (say in the house) or we are trying to interact with something other than the tree. In those cases, just display a generic (but more friendly) message.
So now if we try touching the tree for example and we are either under the tree or in the tree, both locations we should be able to touch the tree from we can do this.
instead of touching the tree: say "You affectionately touch the tree."
Like I mentioned, I went a couple different directions with this, trying to do more with overriding some standard library rules and going down the path of trying to find a way to create some sort of backdrop / supporter. (Something I didn’t try that seems kind of obvious now that I’ve typed all this up is making a separate supporter part of a backdrop and then working with it that way, I suspect that may work, but haven’t tried it)
I haven’t tested this code completely, so there may be some flaws or unintended consequences that I’ve not run across yet. But perhaps this will be useful to someone.
Please feel free to tell me why this is wrong or show me a better way
Edited (9/29/13) to format code a little better