Phantasmal MUD Lib for DGD
Phantasmal Site > Phantasmal Operation > Phrases Using Phrases in PhantasmalPhantasmal 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 FormatsIn 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 TagsThese 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 MarkupIf the current terminal is incapable of the specified piece of display markup, it will be ignored.
Links, Anchors and ReferencesUnless noted otherwise, these are simply ignored if the client isn't able to use them properly.
Protocol
|