Color Guide:
Red indicates a command (or commands) you enter into the MUCK.
Navy indicates text returned by the MUCK, usually a result of a command you typed.
Dynamic Descriptions Using MPI
by Silver of A Bug's Muck
This tutorial will teach you how MPI can be used to dynamically alter the description of your character. We'll build MPI that detects whether a character is awake or asleep, and displays the appropriate description.
First let's look at the description property of a character called Gem.
e gem=/**
dir /_/:(no value)
str /_/de:A young female ant, a few years younger than Dot. Her color is light sky blue with no freckles. Gem is small for her age and appears fragile, but her face is bright and cheery and her large eyes are active and full of curiosity. Her antennae are alert and perky, but droop slightly when at rest.
Like most characters Gem has additional properties, but for this tutorial I've omitted them for simplicity.
Most characters spend a lot of time sleeping while their players are offline, yet others may still look at them. Gem's antennae likely won't be alert and perky when she's asleep, so let's give Gem two descriptions, and use MPI to determine which one is appropriate to display when someone looks at her.
First let's create the two unique descriptions and put each in its own property:
@set gem=_desc_awake:A young female ant, a few years younger than Dot. Her color is light sky blue with no freckles. Gem is small for her age and appears fragile, but her face is bright and cheery and her large eyes are active and full of curiosity. Her antennae are alert and perky, but droop slightly when at rest.
@set gem=_desc_asleep:A young female ant curled up sound asleep, either close up against somebody or in somebody's lap if she has her way. Gem is a few years younger than Dot, and her color is a light sky blue with no freckles. She is small for her age and appears fragile. While sleeping, her countenance is sweetly peaceful, with her antennae drooping about her face.
I chose meaningful names for these properties and used the protected underscore prefix to prevent others from modifying them.
Now we have two descriptions available. The next step is to give the muck a method for choosing which one to display. This situation is fairly simple-- the only condition we care about is whether the character is awake or not. If the character is awake, the muck should display the _desc_awake property, otherwise it should display the _desc_asleep property. In plain english, the situation reads like this:
if awake?
display _desc_awake property
else
display _desc_asleep property
Let's translate this to MPI using the conditional function If. The If function looks like this: {if:condition,true_statement[,false_statement]} The If function looks at the condition and evaluates it. If the condition is true, then it executes whatever the true_statement happens to be. If false, it executes the false_statement. The stuff in the brackets is optional; if a false statement doesn't exist and the condition is false, the function simply returns an empty string. Let's apply this to our situation:
Now we need an MPI function to test the character's 'awake?' condition. Since this is a common muck question, MPI has a built-in function to do the job: Awake, written like this: {awake:player}. If the player is awake, the function will return a number greater than 0, which If evaluates as true. If the player is asleep, the function returns 0, which If evaluates as false.
For the player name in {awake:player} we could use *gem if she is a player-character, or her dbref if she is a puppet, but there is a simpler way to get around all that: use the pre-defined value 'this', which translates to the dbref of the object running the MPI. Simply writing {awake:this} gets the job done. Our MPI code now looks like this:
Next we have to write some MPI to display the two properties. We want to retrieve what is stored in the _desc_awake property and the _desc_asleep property. You can do that with the Prop function, which is written {prop:property}. Let's update our MPI:
We're almost done. Remember that when someone looks at an object, the muck returns whatever is in the _/de property, so we need to replace Gem's _/de description with our new MPI function:
e gem=/**
dir /_/:(no value)
str /_/de:{if:{awake:this},{prop:_desc_awake},{prop:_desc_asleep}}
str /_desc_asleep:A young female ant curled up sound asleep, either close up against somebody or in somebody's lap if she has her way. Gem is a few years younger than Dot, and her color is a light sky blue with no freckles. She is small for her age and appears fragile. While sleeping, her countenance is sweetly peaceful, with her antennae drooping about her face.
str /_desc_awake:A young female ant, a few years younger than Dot. Her color is light sky blue with no freckles. Gem is small for her age and appears fragile, but her face is bright and cheery and her large eyes are active and full of curiosity. Her antennae are alert and perky, but droop slightly when at rest.
That's all there is to it. These same methods can be used to create dynamic descriptions that vary based on other properties. You can test whether the character is OOC or IC and display appropriate descriptions, or test whether the character has a certain item, or is in a certain room, etc. The possibilities are endless.