Manual:DIL Manual/textformat()
Jump to navigation
Jump to search
textformat()
Function (string). Turns the escapes \n and \r in a text into real line breaks.
textformat(s : string)
Returns a copy of s in which each two-character sequence \n becomes a
newline and each \r a carriage return. It is the same translation vmc makes in the
strings of a zone file, so it only matters for text that comes from elsewhere at run time: a
file read with loadstr(), an extra, or what a player typed.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The text. |
Returns
String: the translated copy. A string variable that was never set fails.
Notes
- Nothing else changes. The
&codes of old DikuMUD versions (&n,
&sand the like) and the player's settings play no part any more; text in the game is HTML, with<br/>for a new line.
- Any other backslash pair is kept as it is, and a doubled backslash is no escape:
\\n still gives a backslash and a newline.
Example
dilbegin show_motd(pc : unitptr);
var
err : integer;
motd : string;
code
{
err := loadstr("motd", motd);
if (err > 0)
sendtext(textformat(motd) + "<br/>", pc);
quit;
}
dilend
Reads the message of the day from its file and shows it to a player, as the login in basis.zon does.