User Tools

Site Tools


Sidebar

Passage markup

basics

coding

extra

list

section

whitespace

Macros

basics

colour

data structure

date and time

game state

live

maths

number

revision

saving

showing and hiding

string

styling

url

deprecated

Types of data

Special keywords

Special passage tags

harlowe:text

(text: …[ Number or String or boolean or Array ]) → String

Also known as: (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 number into 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 (num:)) is how you can convert non-string values to a string.

Details:

This macro can also be used much like the (print:) macro - as it evaluates to a string, and strings can be placed in the story source freely,

If you give an 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/text.txt · Last modified: 2017/10/10 00:39 (external edit)