Tips and tricks: handling lists
Welcome to Irregular Ink, our infrequent tips and tricks post series on using ink.

This post is about a little about lists. Lists in ink are (a) very odd, and (b) a big topic with lots of ins and outs, but here's a couple of important first ideas, and some useful functions.

First up, we're really sorry about the name. These lists are not like lists in C#. They aren't arrays. (They're more like a hashset of enums.) We tried calling them sets but "set" is one of the wooliest words in the English language, so we plumped for "list", which is probably the second wooliest. 

A list is: a set (darn) of on/off states, that's always ordered the way you set it up to be. Things can be in the list, or out of it, but that's all. 

More confusingly, a variable list can contain elements from lots of different lists, and they'll still be sorted. 

Ink provides a bunch of ways to handle lists - you can access the full set of states (LIST_ALL), the inverse of the current "on" set (LIST_INVERT), the maximum and minimum "on" values in the current list (LIST_MIN, LIST_MAX).

We can also get the n-th element in a list, if we build a function to do that recursively...

... and best of all perhaps, that lets us choose a random element: 

This idea, of recursively chomping through lists, is incredible powerful. For instance, here's a way of selecting our favourite fruit from a fruit-bowl, using a scoring function.


Thanks for supporting ink, and happy writing!




Inkle released this post 7 days early for patrons.   Become a patron