List Arithmetic

The Pixie
Did you know you can add lists together?

A quick way to get a string list is the Slit command (especially useful for menu options)
l1 = Split("one|two|three", "|")
msg(l1)
-> List: one; two; three;

Now we have a list, we can add strings to it and other string lists:
l2 = "zero" + l1 + "four"
msg(l2)
-> List: zero; one; two; three; four;
l3 = l2 - "two"
msg(l3)
-> List: zero; one; three; four;
l4 = l1 + l3
msg(l4)
-> List: one; two; three; zero; one; three; four;

Also works for object lists:
ol = NewObjectList()
ol2 = ol + player
msg(ol2)

And mixed lists, here in one step I add an object and a string:
l = NewList()
l2 = l + player + "player"

You cannot subtract one list from another, and it does not work for dictionaries.

jaynabonne
That's cool! I had no idea.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums