openclonk/docs/sdk/script/fn/Format.xml

89 lines
3.5 KiB
XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
<func>
<title>Format</title>
<category>Script</category>
<subcat>Strings</subcat>
<version>5.1 OC</version>
<syntax>
<rtype>string</rtype>
<params>
<param>
<type>string</type>
<name>text</name>
<desc>String into which to insert values.</desc>
</param>
<param>
<type/>
<name>...</name>
<desc>Values to be inserted.</desc>
</param>
</params>
</syntax>
<desc>
Composes a string of several values. To do this, text is scanned for placeholders starting with '%' which are then replaced by the parameters.<br/>The general syntax for these placeholders is:<br/><code>%[length][.precision]type</code>Except for type all fields are optional. Type specifies the data type of the parameter to be expected. It can be one of the following values:
<table>
<rowh>
<col>Type</col>
<col>Meaning</col>
</rowh>
<row>
<col>d</col>
<col>Whole number (int)</col>
</row>
<row>
<col>x</col>
<col>Whole number (int), hexadecimal representation (0123456789abcdef)</col>
</row>
<row>
<col>X</col>
<col>Whole number (int), hexadecimal representation (0123456789ABCDEF)</col>
</row>
<row>
<col>i</col>
<col>id (with ids, length and precision parameters do not apply)</col>
</row>
<row>
<col>s</col>
<col>String</col>
</row>
<row>
<col>v</col>
<col>Any. Primarily useful for debugging.</col>
</row>
</table>
Length specifies the minimum number of characters used to display the value. If the value is shorter, the display is padded on the left with space characters, or with zeroes if there is a '0' before the length specification.<br/><br/>The meaning of the precision field varies with the data type: for integers (d) it specifies the minimum display length (the number is padded with zeroes at the beginning); however for strings (s) it specifies the maximum number of characters to be displayed.<br/>
</desc>
<examples>
<example>
<code><funclink>Log</funclink>(Format(&quot;Hello, %s.You have %d Clonks!&quot;, <funclink>GetPlayerName</funclink>(0), <funclink>GetCrewCount</funclink>(0)));</code>
<text>Displays "Hello Twonky, you have 3 Clonks!" (names vary).</text>
</example>
<example>
<code><funclink>Log</funclink>(Format(&quot;'%3d'&quot;, 1));</code>
<text>Displays: ' 1'</text>
</example>
<example>
<code><funclink>Log</funclink>(Format(&quot;'%i'&quot;, <funclink>GetID</funclink>(<funclink>GetCursor</funclink>())));</code>
<text>Displays (e.g.): 'Clonk'</text>
</example>
<example>
<code><funclink>Log</funclink>(Format(&quot;'%3.2d'&quot;, 5));</code>
<text>Displays: ' 05'</text>
</example>
<example>
<code><funclink>Log</funclink>(Format(&quot;'%.2s'&quot;, &quot;test&quot;));</code>
<text>Displays: 'te'</text>
</example>
<example>
<code><funclink>Log</funclink>(Format(&quot;'%03d'&quot;, 12));</code>
<text>Displays: '012'</text>
</example>
</examples>
</func>
<author>Sven2</author><date>2001-11</date>
</funcs>