bagBag
returns bag?
bagBag(bag: bag, key: string) -> bag?
The bag nested under a key, or none when the key is missing or holds something that is not a bag.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to read |
| keyrequired |
string |
the field to look under |
Example
if bagBag(newBag(), "stats") == none { print("unset") }
bagBags
returns list<bag>
bagBags(bag: bag, key: string) -> list<bag>
The list of bags stored under a key, or an empty list when the key is missing or holds something else — so a for loop over it is always safe.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to read |
| keyrequired |
string |
the field to look under |
Example
print(count(bagBags(newBag(), "rows")))
bagFlag
returns bool?
bagFlag(bag: bag, key: string) -> bool?
The flag stored under a key, or none when the key is missing or holds something that is not a flag.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to read |
| keyrequired |
string |
the field to look under |
Example
if bagFlag(newBag(), "alive") == none { print("unset") }
bagFlagOr
returns bool
bagFlagOr(bag: bag, key: string, fallback: bool) -> bool
The flag under a key, or the fallback when the key is missing or holds something else. Never none — the right shape for a condition.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to read |
| keyrequired |
string |
the field to look under |
| fallbackrequired |
bool |
the answer when the field is missing |
Example
if bagFlagOr(newBag(), "alive", false) { print("up") }
bagHas
returns bool
bagHas(bag: bag, key: string) -> bool
True when the bag has a field under that key, whatever its type.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to ask |
| keyrequired |
string |
the field to look for |
Example
if bagHas(newBag(), "hp") { print("set") }
bagInc
does something
bagInc(bag: bag, key: string, by: int)
Adds to a number field in place, treating a missing or non-number field as 0 first — the per-row tally. Faults on overflow.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to count on |
| keyrequired |
string |
the number field to grow |
| byrequired |
int |
what to add; negative subtracts |
Example
bagInc(newBag(), "kills", 1)
bagKeys
returns list<string>
bagKeys(bag: bag) -> list<string>
Every field name in the bag, in the order they were first put — walk it with for to see what a bag holds.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to list |
Example
for k in bagKeys(newBag()) { print(k) }
bagList
returns list<bag>
bagList() -> list<bag>
An empty list of bags, ready to append rows into. Lists are immutable as ever: append answers a new list, so write table = append(table, row).
Example
let table = bagList() print(count(bagList()), count(table))
bagNumber
returns int?
bagNumber(bag: bag, key: string) -> int?
The number stored under a key, or none when the key is missing or holds something that is not a number.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to read |
| keyrequired |
string |
the field to look under |
Example
if bagNumber(newBag(), "hp") == none { print("unset") }
bagNumberOr
returns int
bagNumberOr(bag: bag, key: string, fallback: int) -> int
The number under a key, or the fallback when the key is missing or holds something else. Never none — the right shape for a readout.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to read |
| keyrequired |
string |
the field to look under |
| fallbackrequired |
int |
the answer when the field is missing |
Example
print(bagNumberOr(newBag(), "hp", 0))
bagNumbers
returns list<int>
bagNumbers(bag: bag, key: string) -> list<int>
The list of numbers stored under a key, or an empty list when the key is missing or holds something else — so a for loop over it is always safe.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to read |
| keyrequired |
string |
the field to look under |
Example
print(count(bagNumbers(newBag(), "prices")))
bagOf
returns bag
bagOf(key: string, value: int) -> bagbagOf(key: string, value: string) -> bagbagOf(key: string, value: bool) -> bag
A new bag already holding one number field — the short way to start one.
A new bag already holding one text field — the short way to start one.
A new bag already holding one flag field — the short way to start one.
| Parameter | Type | What it does |
| keyrequired |
string |
the first field's name |
| valuerequired |
int |
the number to store under it |
Example
let b = bagOf("hp", 30) print(b)
let b = bagOf("name", "guard") print(b)
let b = bagOf("alive", true) print(b)
bagPut
does something
bagPut(bag: bag, key: string, value: int)bagPut(bag: bag, key: string, value: string)bagPut(bag: bag, key: string, value: bool)bagPut(bag: bag, key: string, value: tile)bagPut(bag: bag, key: string, value: bag)bagPut(bag: bag, key: string, value: list<int>)bagPut(bag: bag, key: string, value: list<string>)bagPut(bag: bag, key: string, value: list<tile>)bagPut(bag: bag, key: string, value: list<bag>)
Sets one field on a bag, replacing what was under the key. A bag holds up to 512 fields; past that this refuses rather than growing without end.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to write into |
| keyrequired |
string |
the field's name, up to 128 characters |
| valuerequired |
int |
the number to store |
Example
bagPut(newBag(), "hp", 30)
bagPut(newBag(), "name", "guard")
bagPut(newBag(), "alive", true)
bagPut(newBag(), "spot", myTile())
bagPut(newBag(), "stats", newBag())
bagPut(newBag(), "prices", range(0, 3))
bagPut(newBag(), "names", split("a,b", ","))
bagPut(newBag(), "route", path(myTile()))
bagPut(newBag(), "rows", bagList())
bagRemove
does something
bagRemove(bag: bag, key: string)
Removes one field from a bag. Removing a field that is not there does nothing, so it is safe to tidy unconditionally.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to take the field off |
| keyrequired |
string |
the field to remove; missing is fine |
Example
bagRemove(newBag(), "stale")
bagSize
returns int
bagSize(bag: bag) -> int
How many fields the bag holds right now.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to measure |
Example
print("fields", bagSize(newBag()))
bagText
returns string?
bagText(bag: bag, key: string) -> string?
The text stored under a key, or none when the key is missing or holds something that is not text.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to read |
| keyrequired |
string |
the field to look under |
Example
if bagText(newBag(), "name") == none { print("unset") }
bagTextOr
returns string
bagTextOr(bag: bag, key: string, fallback: string) -> string
The text under a key, or the fallback when the key is missing or holds something else. Never none — the right shape for a readout.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to read |
| keyrequired |
string |
the field to look under |
| fallbackrequired |
string |
the answer when the field is missing |
Example
print(bagTextOr(newBag(), "name", "?"))
bagTexts
returns list<string>
bagTexts(bag: bag, key: string) -> list<string>
The list of texts stored under a key, or an empty list when the key is missing or holds something else — so a for loop over it is always safe.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to read |
| keyrequired |
string |
the field to look under |
Example
print(count(bagTexts(newBag(), "names")))
bagTile
returns tile?
bagTile(bag: bag, key: string) -> tile?
The tile stored under a key, or none when the key is missing or holds something that is not a tile.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to read |
| keyrequired |
string |
the field to look under |
Example
if bagTile(newBag(), "spot") == none { print("unset") }
bagTiles
returns list<tile>
bagTiles(bag: bag, key: string) -> list<tile>
The list of tiles stored under a key, or an empty list when the key is missing or holds something else — so a for loop over it is always safe.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to read |
| keyrequired |
string |
the field to look under |
Example
print(count(bagTiles(newBag(), "route")))
bagWipe
does something
bagWipe(bag: bag)
Empties a bag of every field, keeping the bag itself — every variable holding it now sees it empty.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to empty |
Example
bagWipe(newBag())
bagsWhere
returns list<bag>
bagsWhere(rows: list<bag>, key: string, value: int) -> list<bag>bagsWhere(rows: list<bag>, key: string, value: string) -> list<bag>bagsWhere(rows: list<bag>, key: string, value: bool) -> list<bag>
The rows whose field equals a value, in their original order, the input unchanged. A row without the field never matches.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to filter |
| keyrequired |
string |
the field to test in every row |
| valuerequired |
int |
the number the field must equal |
Example
print(count(bagsWhere(bagList(), "hp", 30)))
print(count(bagsWhere(bagList(), "name", "guard")))
print(count(bagsWhere(bagList(), "alive", true)))
bagsWhereAtLeast
returns list<bag>
bagsWhereAtLeast(rows: list<bag>, key: string, threshold: int) -> list<bag>
The rows whose number under a key is at least the threshold, in their original order. A row without the column never matches.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to filter |
| keyrequired |
string |
the number column to test in every row |
| thresholdrequired |
int |
the number the column is measured against |
Example
print(count(bagsWhereAtLeast(bagList(), "lvl", 60)))
bagsWhereAtMost
returns list<bag>
bagsWhereAtMost(rows: list<bag>, key: string, threshold: int) -> list<bag>
The rows whose number under a key is at most the threshold, in their original order. A row without the column never matches.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to filter |
| keyrequired |
string |
the number column to test in every row |
| thresholdrequired |
int |
the number the column is measured against |
Example
print(count(bagsWhereAtMost(bagList(), "lvl", 40)))
bagsWhereNot
returns list<bag>
bagsWhereNot(rows: list<bag>, key: string, value: int) -> list<bag>bagsWhereNot(rows: list<bag>, key: string, value: string) -> list<bag>bagsWhereNot(rows: list<bag>, key: string, value: bool) -> list<bag>
The rows whose field does NOT equal a value — including rows without the field at all. The complement of bagsWhere.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to filter |
| keyrequired |
string |
the field to test in every row |
| valuerequired |
int |
the number the field must equal |
Example
print(count(bagsWhereNot(bagList(), "hp", 30)))
print(count(bagsWhereNot(bagList(), "name", "guard")))
print(count(bagsWhereNot(bagList(), "alive", true)))
bagsWhereOver
returns list<bag>
bagsWhereOver(rows: list<bag>, key: string, threshold: int) -> list<bag>
The rows whose number under a key is strictly over the threshold, in their original order. A row without the column never matches.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to filter |
| keyrequired |
string |
the number column to test in every row |
| thresholdrequired |
int |
the number the column is measured against |
Example
print(count(bagsWhereOver(bagList(), "hp", 50)))
bagsWhereUnder
returns list<bag>
bagsWhereUnder(rows: list<bag>, key: string, threshold: int) -> list<bag>
The rows whose number under a key is strictly under the threshold, in their original order. A row without the column never matches.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to filter |
| keyrequired |
string |
the number column to test in every row |
| thresholdrequired |
int |
the number the column is measured against |
Example
print(count(bagsWhereUnder(bagList(), "hp", 10)))
copyBag
returns bag
copyBag(bag: bag) -> bag
A new bag with the same fields as this one. Shallow: a nested bag is shared, not copied — copy it too if you need it separate.
| Parameter | Type | What it does |
| bagrequired |
bag |
the bag to copy |
Example
let b2 = copyBag(newBag()) print(b2)
distinctBagsBy
returns list<bag>
distinctBagsBy(rows: list<bag>, key: string) -> list<bag>
The rows with later duplicates of a column removed — the first row with each value stays, in order. Rows without the column all count as sharing one blank value, so the first of those stays too.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to thin |
| keyrequired |
string |
the column two rows may not share |
Example
print(count(distinctBagsBy(bagList(), "name")))
findBag
returns bag?
findBag(rows: list<bag>, key: string, value: int) -> bag?findBag(rows: list<bag>, key: string, value: string) -> bag?findBag(rows: list<bag>, key: string, value: bool) -> bag?
The FIRST row whose field equals a value, or none when no row matches — the table lookup, one call.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to search |
| keyrequired |
string |
the field to test in every row |
| valuerequired |
int |
the number the field must equal |
Example
if findBag(bagList(), "hp", 30) == none { print("no row") }
if findBag(bagList(), "name", "guard") == none { print("no row") }
if findBag(bagList(), "alive", true) == none { print("no row") }
maxBagBy
returns bag?
maxBagBy(rows: list<bag>, key: string) -> bag?
The row with the LARGEST number under a key — the leaderboard's top row. None when no row has the column. Ties answer the earliest row.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to search |
| keyrequired |
string |
the number column to compare |
Example
if maxBagBy(bagList(), "xp") == none { print("no rows") }
meanBags
returns int?
meanBags(rows: list<bag>, key: string) -> int?
The average of a number column across the rows that have it, rounded toward zero. None when no row has the column.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to fold |
| keyrequired |
string |
the number column to average |
Example
print(meanBags(bagList(), "hp"))
mergeBags
returns bag
mergeBags(base: bag, over: bag) -> bag
A new bag holding both bags' fields; where both have a key, 'over' wins. Neither input is changed.
| Parameter | Type | What it does |
| baserequired |
bag |
the bag whose fields come first |
| overrequired |
bag |
the bag whose fields win a clash |
Example
print(mergeBags(newBag(), bagOf("hp", 30)))
minBagBy
returns bag?
minBagBy(rows: list<bag>, key: string) -> bag?
The row with the SMALLEST number under a key — the whole row, not the number. None when no row has the column. Ties answer the earliest row.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to search |
| keyrequired |
string |
the number column to compare |
Example
if minBagBy(bagList(), "hp") == none { print("no rows") }
newBag
returns bag
newBag() -> bag
A fresh, empty bag — the script's own record. Give it fields with bagPut and read them back with the typed bag reads.
Example
let b = newBag() print(newBag(), b)
pluckNumbers
returns list<int>
pluckNumbers(rows: list<bag>, key: string) -> list<int>
One column of a table as a list: every row's number under the key, rows without one skipped — feed it to sum, mean or sorted.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to read down |
| keyrequired |
string |
the number column to collect |
Example
print(sum(pluckNumbers(bagList(), "hp")))
pluckTexts
returns list<string>
pluckTexts(rows: list<bag>, key: string) -> list<string>
One column of a table as a list: every row's text under the key, rows without one skipped — the text partner of pluckNumbers.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to read down |
| keyrequired |
string |
the text column to collect |
Example
print(count(pluckTexts(bagList(), "name")))
sortBagsBy
returns list<bag>
sortBagsBy(rows: list<bag>, key: string) -> list<bag>
The rows ordered by a number column, smallest first, rows without the column last, the input unchanged. sortBagsByDesc turns it round.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to order |
| keyrequired |
string |
the number column to order by, smallest first |
Example
print(count(sortBagsBy(bagList(), "hp")))
sortBagsByDesc
returns list<bag>
sortBagsByDesc(rows: list<bag>, key: string) -> list<bag>
The rows ordered by a number column, largest first, rows without the column last, the input unchanged — the leaderboard order.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to order |
| keyrequired |
string |
the number column to order by, largest first |
Example
print(count(sortBagsByDesc(bagList(), "xp")))
sumBags
returns int
sumBags(rows: list<bag>, key: string) -> int
The total of a number column across every row, rows without it counting 0 — the one-call table sum. Faults on overflow.
| Parameter | Type | What it does |
| rowsrequired |
list<bag> |
the table to fold |
| keyrequired |
string |
the number column to add up |
Example
print(sumBags(bagList(), "xp"))