int
int <string>
Parse a string as a base-10 integer.
This is the explicit string-to-int conversion. There is no implicit
coercion from strings to numbers, so use int whenever you need to do
arithmetic or numeric comparison on text — for example the words of
$args or a value read back with
recall.
Arguments
<string>— the text to parse. It must be a base-10 integer, optionally signed (-5,42); any other content is a parse failure.
Returns
An int — the parsed value.
If the string does not parse as a base-10 integer, that is a run-time error and the execution stops (see control flow and the parse-failure rule in values). There is no fallback value; guard the input if it might not be numeric.
Examples
after command (say) {
do "say [int "42"] is the answer."
}
[int "42"] evaluates to the integer 42, so the mob says
"42 is the answer."
Convert text before arithmetic with the operators:
after command (say) {
let count [int [first $args]]
do "say Doubled, that is [* $count 2]."
}
The first word of the command line is parsed to an int, then doubled.
If that word is not a number — say the player typed say apples — int
raises a run-time error and the handler stops.