Phantasmal MUD Lib for DGD

Phantasmal Site > Phantasmal Operation > Phrases

Using Phrases in Phantasmal

Phantasmal uses structures called 'Phrases' to handle most output to the user. Phrases are a bit like strings in other MUDs, but they do a number of other things for you as well. However, they can require careful handling.

The first and simplest thing to remember about a Phrase is that it is not really a string. You may use it in the same places you'd expect to use a string, but it's not the same thing. That's because Phantasmal holds itself to a higher standard on some things, and that means it winds up holding you to a higher standard on some of them. There are ways that your MUD isn't going to be allowed to suck, whether you're willing to let it or not :-)

A Phrase can be thought of as being a string in a MUD markup language. A markup language like HTML contains text, but it also contains tags that mean various things about the text. You can have simple markup tags for what color something is supposed to be or whether it's supposed to be in italics. You can have more interesting semantic markup — that is, markup about the meaning of the text, not how it gets drawn — to mark a particular piece of text as being an attack, or an exit, or in Spanish or Dwarvish.

Phantasmal can use any of several different markup languages. One markup language is similar to HTML or XML, in the same way that some web sites use simplified HTML for comments. However, the Phrase converts this markup into a binary internal format for speed. So to edit a Phrase as markup, you'll need to export it as ASCII using a function like to_xml(). You can then edit it as markup and set the Phrase to a new value with from_xml(). Be sure to preserve tags, and to tag your text appropriately!

One unusual thing about Phantasmal markup is the language tags. Sometimes, the outermost tags of a Phrase will be "enUS", "esES" or similar location tags. Note that this format for language names refers to the language and then the country, so "enUS" refers to the English language as spoken in the United States of America, while "enUK" would be English in the United Kingdom. (Note: how will a set of alternative language versions of the same piece of text work? If we mark those, we can have less-favorite languages easily)

For instance, a fine piece of XML markup might be "<enUS>The goblin leaves <green>west</green>.</enUS> <esUS>El goblin sale <verde>oeste</verde>.</esUS>" Note the two different language choices as the outermost tags, at the same level as each other.

HTML has certain tags that don't have matching end-tags. For instance, the <hr> tag. When doing fully-balanced HTML such as strict xHTML, this is written <hr /> to indicate to the parser that no matching end-tag is expected. This form is strongly preferred in Phantasmal as well, though we'll try to put up with whatever we can.


Markup Formats

In addition to the XML markup format above, there is an UNQ markup format. The UNQ format uses tags with the same names, but the start and end markers are changed to a single label and then curly braces surrounding the appropriate text. An UNQ tag which stands alone just has an empty pair of curly braces after it.

So, for instance the equivalent of the above would be "~enUS{The goblin leaves ~green{west}} ~esUS{El goblin sale ~verde{oeste}}".

Phrases may also be able to return UNQ data markup, which is the equivalent of running the above UNQ through the UNQ parser. However, it will usually be possible to generate UNQ data more quickly by doing it directly than by generating the UNQ string and then parsing.

There is also a format called 'taglist' format, used by programs, that doesn't have a direct text representation. A taglist is an array of even length which alternates between tag, text, tag, text, et cetera. If there's no tag around the opening text, the first element of the list is an empty string. Instead of having nested tagged text like the UNQ markup, the taglist is a single flat list. Tag names start with an opening or closing curly brace to indicate whether they're opening or closing a tag's scope, or an asterisk to indicate that the tag is freestanding and doesn't enclose any other list items.

The taglist equivalent of the UNQ markup "~enUS{~monster{~green{The goblin}} hits the ~target{}!}" would be the DGD array ({ "{enUS", "", "{monster", "", "{green", "The goblin", "}green", "", "}monster", "hits the", "*target", "!", "}enUS", "" }).

Tags in a taglist should always be perfectly nested. So it would be illegal to have a taglist like ({ "{green", "bob", "{red", "sam", "}green", "", "}red", "" }). It is also illegal to have an opening tag without a corresponding closing tag.


Markup Tags

These are currently tentative — we may well change them. They're designed to work with the appropriate various we-hope-to-support terminal types. That would include MXP, MSP, MCP, IMP (FireClient), Pueblo, XMLTerm, VT100. They don't span the full capabilities of all those terminals, but are meant to translate tolerably into all of them.

The tags may be translated differently into different languages, like the "verde" tag in the example markup above, eventually. I'll need somebody to care more about that than I currently do... HTML doesn't seem to do that, which is one reason I'm not yet bothering.

Display Markup

If the current terminal is incapable of the specified piece of display markup, it will be ignored.

<b>
Boldface
<i>
Italics
<u>
Underline
<strikethru>
Strike-through text
<superscript>
Display text as superscript. If there is a number inside the tag, that's the amount to superscript by.
<subscript>
Display text as superscript. If there is a number inside the tag, that's the amount to subscript by.
<font [color=<color>] [face=<font name>]>
Attempt to display the text in the given font. It's not clear how we'll do this even vaguely portably.
<pre>
HTML-style preformatting tag
<blockquote>
HTML-style block quoting tag
<br />
Line break
<hr />
Horizontal rule
<ol>
HTML-style ordered list
<ul>
HTML-style unordered list
<li>
HTML-style list item
<alert-beep />
An alert beep to get the user's attention
<center>
Attempt to center text. May interact oddly with linebreaks.
<clear-screen>
Clear the text window.
<background #<number>>
Display background in the specified color, interpreted as hexadecimal RGB
<black>
ANSI color, approximately
<blue>
ANSI color, approximately
<green>
ANSI color, approximately
<cyan>
ANSI color, approximately
<red>
ANSI color, approximately
<purple>
ANSI color, approximately
<brown>
ANSI color, approximately
<gray> (also <grey>)
ANSI color, approximately
<dkgray> (also <dkgrey>)
ANSI color, approximately
<ltblue>
ANSI color, approximately
<ltgreen>
ANSI color, approximately
<ltcyan>
ANSI color, approximately
<ltred>
ANSI color, approximately
<ltpurple>
ANSI color, approximately
<yellow>
ANSI color, approximately
<white>
ANSI color, approximately

Links, Anchors and References

Unless noted otherwise, these are simply ignored if the client isn't able to use them properly.

<command>
MUD command - sent back to MUD if clicked
<url>
Link to (external, outside the MUD) URL
<url-in-window />
Open the URL in a new window, or keep one window for all url-in-window requests. This doesn't need to be clicked on.
<play-audio-url>
Play the audio file at the specified URL
<stop-audio />
Stop any currently-playing audio
<image-url alt="" height=# width=#>
Show the specified image, or the 'alt' tag if it is specified and the image cannot be displayed
<prefetch>
Prefetch the specified content with the expectation that it will be the subject of an img, play-audio-url, url or url-in-window tag soon

Protocol

<client-startup />
Show the terminal type and possibly similar information like <IMPDEMO>
<ip-address />
Display the client's IP address
<connect />
Connect to current location
<disconnect />
Disconnect from current location
<reconnect />
Reconnect to current location
<new-connect host=host port=port />
Connect to new location