This shows you the differences between two versions of the page.
— |
harlowe:text [2017/10/09 20:39] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | **(text: // ...[ [[harlowe:Number|Number]] or [[harlowe:String|String]] or [[harlowe:Boolean|boolean]] or [[harlowe:Array|Array]] ]//) -> //String//** | ||
+ | Also known as: [[harlowe:string|(string:)]] | ||
+ | |||
+ | (text:) accepts any amount of expressions and tries to convert them all | ||
+ | to a single String. | ||
+ | |||
+ | === Example usages: === | ||
+ | |||
+ | * ''%%(text: $cash + 200)%%'' | ||
+ | * ''%%(if: (text: $cash)'s length > 3)[Phew! Over four digits!]%%'' | ||
+ | * ''%%(text: ...$arr)%%'' | ||
+ | |||
+ | === Rationale: === | ||
+ | |||
+ | Unlike in Twine 1 and SugarCube, Twine 2 will only convert [[harlowe:number|number]] into [[harlowe:string|string]], or strings | ||
+ | into numbers, if you explictly ask it to. This extra carefulness decreases | ||
+ | the likelihood of unusual bugs creeping into stories (such as adding 1 and "22" | ||
+ | and getting "122"). The (text:) macro (along with [[harlowe:num|(num:)]]) is how you can convert | ||
+ | non-string values to a string. | ||
+ | |||
+ | === Details: === | ||
+ | |||
+ | This macro can also be used much like the [[harlowe:print|(print:)]] macro - as it evaluates to a | ||
+ | string, and strings can be placed in the story source freely, | ||
+ | |||
+ | If you give an [[harlowe:Array|Array]] to (text:), it will attempt to convert every element | ||
+ | contained in the array to a String, and then join them up with commas. So, | ||
+ | ''%%(text: (a: 2, "Hot", 4, "U"))%%'' will result in the string "2,Hot,4,U". | ||
+ | If you'd rather this not occur, you can also pass the array's individual | ||
+ | elements using the ''%%...%%'' operator - this will join them with nothing in between. | ||
+ | So, ''%%(text: ...(a: 2, "Hot", 4, "U"))%%'' will result in the string "2Hot4U". | ||
+ | |||
+ | === See also: === | ||
+ | |||
+ | [[harlowe:num|(num:)]] |