Difference between revisions of "Manual:DIL Manual/itoa()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = itoa() = | |
| − | + | '''Function''' (string). An integer written as text. | |
| − | |||
| − | |||
| − | |||
| − | + | itoa(i : integer) : string | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Turns a number into its decimal text, with a minus sign when it is negative, so it can be joined to other strings with <code>+</code>. DIL doesn't turn numbers into text by itself: <code>"You have " + self.hp</code> doesn't compile. | |
| + | |||
| + | == Parameters == | ||
| + | {| class="wikitable" | ||
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | i || integer || The number. | ||
| + | |} | ||
| + | |||
| + | == Returns == | ||
| + | The text: <code>itoa(42)</code> is <code>"42"</code>, <code>itoa(-7)</code> is <code>"-7"</code>. When <code>i</code> fails (for example a field of a null unit), the call fails too and a string variable assigned from it is emptied. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin show_hp(); | ||
| + | code | ||
| + | { | ||
| + | sendtext("You have " + itoa(self.hp) + " of " + itoa(self.max_hp) | ||
| + | + " hit points.<br/>", self); | ||
| + | quit; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Shows a character its hit points. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/atoi()|atoi()]] | ||
| + | * [[Manual:DIL Manual/moneystring()|moneystring()]] | ||
Latest revision as of 23:17, 14 November 2026
itoa()
Function (string). An integer written as text.
itoa(i : integer) : string
Turns a number into its decimal text, with a minus sign when it is negative, so it can be joined to other strings with +. DIL doesn't turn numbers into text by itself: "You have " + self.hp doesn't compile.
Parameters
| Name | Type | Meaning |
|---|---|---|
| i | integer | The number. |
Returns
The text: itoa(42) is "42", itoa(-7) is "-7". When i fails (for example a field of a null unit), the call fails too and a string variable assigned from it is emptied.
Example
dilbegin show_hp();
code
{
sendtext("You have " + itoa(self.hp) + " of " + itoa(self.max_hp)
+ " hit points.<br/>", self);
quit;
}
dilend
Shows a character its hit points.