Difference between revisions of "Manual:DIL Manual/textformat()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = textformat() = | |
| − | + | '''Function''' (string). Turns the escapes <code>\n</code> and <code>\r</code> in a text into real line breaks. | |
| − | |||
| − | |||
| − | + | textformat(s : string) | |
| − | |||
| − | + | Returns a copy of <code>s</code> in which each two-character sequence <code>\n</code> becomes a | |
| − | + | newline and each <code>\r</code> 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 [[Manual:DIL Manual/loadstr()|loadstr()]], an extra, or what a player typed. | ||
| + | == Parameters == | ||
| + | {| class="wikitable" | ||
| + | ! 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 <code>&</code> codes of old DikuMUD versions (<code>&n</code>, | |
| + | <code>&s</code> and the like) and the player's settings play no part any more; text in the | ||
| + | game is HTML, with <code><br/></code> for a new line. | ||
| + | * Any other backslash pair is kept as it is, and a doubled backslash is no escape: | ||
| + | <code>\\n</code> still gives a backslash and a newline. | ||
| − | + | == Example == | |
| − | + | <pre> | |
| − | + | 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 | ||
| + | </pre> | ||
| + | Reads the message of the day from its file and shows it to a player, as the login in basis.zon | ||
| + | does. | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/loadstr()|loadstr()]] | |
| + | * [[Manual:DIL Manual/sendtext()|sendtext()]] | ||
| + | * [[Manual:DIL Manual/replace()|replace()]] | ||
Latest revision as of 23:20, 14 November 2026
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.