Looking through a Window
Another simple MPI project. This time we're going to add some MPI to the description of a door, window, or other item that would allow you to see into another room (magic mirror anyone?) Once again the key to the effect is good descriptions so give them a lot of thought.
Since this bit of MPI can be inserted in any description it can be used on objects, rooms, looktraps (properties stored on objects and rooms), and even on yourself (if you play a gelatinous cube or something I guess).
Start with the description of your door:
The thick oaken door stands ajar, revealing a Victorian style ladies sitting room. (The MPI will go here when I write it)
Now for the MPI.
We need to know if anyone is in the room first and insert various lines of text based on the number present. So we start with an {if:} statement:
{if:(some expression to check if anyone is in the room),(what to do if the room is empty),(what do if it is not)}
We'll put in the easy stuff first. A couple of {exec:} primitives:
{if:(some expression to check if anyone is in the
room),
{exec:_contents/empty,this},{exec:_contents/players,this}}
The first {exec:} is the true case. Since it's easier to check if a room is empty I'm going to use that for the true case and let anything else (be it 1 player or 100 players) be the false. Notice the second argument in the {exec:} primitive is this, that indicates to the MUCK to check the object for the properties _contents/empty and _contents/players.
Now we need our conditional expression. Since I've decided to use no players in the room as the true I'm going to use an {eq:} expression to compare the number of players to 0. Then I just need to find out how many players are in the room which I can do with {count:} and {contents:}.
{eq:{count:{contents:#1234,player}},0}
Starting from the middle of the expression, {contents:} is a primitive with two arguments, the room to check in, and the type of object to look for. In this case I'm checking my room #1234 (use your own room db# of course) for objects of type player.
The primitive {count:} simply counts the number of objects found by {contents:}. And of course {eq:} compares the count to 0.
Putting it all together you get:
The thick oaken door stands ajar, revealing a Victorian style
ladies sitting room. {if:{eq:{count:{contents:#1234,player}},0},{exec:_contents/empty,this},
{exec:_contents/players,this}}
Note: Your MPI must be all on one line! Unless you want it on a separate line it should be inserted in your description like a sentence, with leading and trailing spaces.
Now we need to make the properties _contents/empty and _contents/players.
The empty case is simple, it's just a description of the empty room. It could be as simple as "There is no one inside."
@set door=_contents/empty:There is no one inside.
Now when there are people in the room we need to get more exotic. However we're going to simplify it a bit by naming the people inside. (Yes, in this case keeping the players anonymous is more complicated.)
Above you saw the primitive {contents:} used inside a {count:} to get the number of players in the room. The primitive {contents:} creates a list of all the objects inside that match the type it's searching for so we're going to use it again, this time with a different primitive:
@set door=_contents/players:You see {commas:{contents:#1234,player},\, and ,playerdb,{name:{&playerdb}}} resting inside.
Let's break down the MPI in this property:
{commas:{contents:#1234,player},\, and ,playerdb,{name:{&playerdb}}}
The first item in {commas:} is the list to put commas into. Here we're getting the list from the primitive {contents:}
The second item is the last separator it should use between the last two items of the list (or in a list of two items, the only items of the list). I'm using ", and " (note the spaces). Also notice that I had to escape the comma with a backslash (\, and ) to keep {commas:} from getting confused.
The last two items are there to convert the db#s of the players to their names.
The first item is the name of the variable {commas:} will use for each item of the list as it processes it.
The second item is the expression to be evaluated with the variable. In this case {name:}, which will turn the db# into the name of the player. The result of the expression is what actually gets used by {commas:} when it makes its string.
With everything in place you now have the following description on the door when the room is empty:
The thick oaken door stands ajar, revealing a Victorian style ladies sitting room. There is no one inside.
When Maybeline is inside:
The thick oaken door stands ajar, revealing a Victorian style ladies sitting room. You see Maybeline resting inside.
When Maybeline and Anabelle are inside:
The thick oaken door stands ajar, revealing a Victorian style ladies sitting room. You see Maybeline, and Anabelle resting inside.
When Maybeline, Anabelle, and Beatrice are inside:
The thick oaken door stands ajar, revealing a Victorian style ladies sitting room. You see Maybeline, Anabelle, and Beatrice resting inside.
And so on.
You could of course get fancy and check to see if there were exactly 2 players in the room and set up a different property with a {commas:} that would just use " and " as the separator if having the extra comma there bothers you. Or you could leave the blackslashed comma in my {commas:} out entirely which would leave the case of three or more players like this:
The thick oaken door stands ajar, revealing a Victorian style ladies sitting room. You see Maybeline, Anabelle and Beatrice resting inside.
The decision is entirely up to you.
Code Main