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
Tier Benefits
Pledge $0 or more per month
patrons
Everyone
Pledge $0.01 or more per month
patrons
Patrons Only
Thank-you!
$2 or more per month 53 patrons
All our reward levels come with one perk - early-access to our tips and tricks blog posts here on the Patreon site. 


This level is recommended for hobbyists and dabblers.

Sincere thanks!
$5 or more per month 16 patrons
All our reward levels come with one perk - early-access to our tips and tricks blog posts here on the Patreon site.


This level is recommended for independent creators.

Corporate generosity, because that's a thing
$25 or more per month 2 patrons
All our reward levels come with one perk - early-access to our tips and tricks blog posts here on the Patreon site. 


This level is recommended for successful studios using ink as part of your pipeline.

Recent Posts