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:sorted

(sorted: Number or String, …Number or String) → Array

Similar to (a:), except that it requires only number or string, and orders them in English alphanumeric sort order, rather than the order in which they were provided.

Example usage:

(set: $a to (a: 'A','C','E','G', 2, 1))
(print: (sorted: ...$a))

Rationale:

Often, you'll be using array as 'decks' that will provide values to other parts of your story in a specific order. If you want, for instance, several strings to appear in alphabetical order, this macro can be used to create a sorted array, or (by using the spread ... syntax) convert an existing array into a sorted one.

Details:

Unlike other programming languages, strings aren't sorted using ASCII sort order, but alphanumeric sorting: the string “A2” will be sorted after “A1” and before “A11”. Moreover, if the player's web browser supports internationalisation (that is, every current browser except Safari 6-8 and IE 10), then the strings will be sorted using English language rules (for instance, “é” comes after “e” and before “f”, and regardless of the player's computer's language settings. Otherwise, it will sort using ASCII comparison (whereby “é” comes after “z”).

Currently there is no way to specify an alternative language locale to sort by, but this is likely to be made available in a future version of Harlowe.

To ensure that it's being used correctly, this macro requires two or more items - providing just one (or none) will cause an error to be presented.

See also:

harlowe/sorted.txt · Last modified: 2017/06/18 22:21 by l