User Tools

Site Tools


harlowe:num

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

harlowe:num [2017/10/09 20:39] (current)
Line 1: Line 1:
 +**(num: // [[harlowe:​String|String]]//​) -> //​[[harlowe:​Number|Number]]//​**
  
 +Also known as: [[harlowe:​number|(number:​)]]
 +
 +This macro converts [[harlowe:​string|strings]] to [[harlowe:​number|numbers]] by reading the digits in the entire
 +string. It can handle decimal fractions and negative numbers.
 +If any letters or other unusual characters appear in the number, it will
 +result in an error.
 +
 +=== Example usage: ===
 +
 +''​%%(num:​ "​25"​)%%''​ results in the number ''​%%25%%''​.
 +
 +=== Rationale: ===
 +
 +Unlike in Twine 1 and SugarCube, Twine 2 will only convert numbers into strings, or strings
 +into numbers, if you explictly ask it to using macros such as this. This extra
 +carefulness decreases the likelihood of unusual bugs creeping into stories
 +(such as performing ''​%%"​Eggs:​ " + 2 + 1%%''​ and getting ''​%%"​Eggs:​ 21"​%%''​).
 +
 +Usually, you will only work with numbers and strings of your own creation, but
 +if you're receiving user input and need to perform arithmetic on it,
 +this macro will be necessary.
 +
 +=== See also: ===
 +
 +[[harlowe:​text|(text:​)]]
harlowe/num.txt ยท Last modified: 2017/10/09 20:39 (external edit)