Learn Lua · Tables · Lesson 1 of 5
Lists
A list is a table of values in order: { "Flyer", "Card", "Poster" }. Positions
start at 1, and # gives the length:
local items = { "Flyer", "Card", "Poster" }
items[1] --> "Flyer"
#items --> 3In the Input line, { string } means a list of strings.
table.insert adds to the end. It changes the list itself, so copy a list with
table.clone first when you shouldn't change the original:
local more = table.clone(items)
table.insert(more, "Sticker")
#more --> 4
#items --> 3What your code receives
Your code gets its data as input. The type Input line at the top of the code lists every field, and the editor uses it to suggest field names and spot typos. Here is an example. Each check sends different values, so work from the fields rather than these exact values.
input = { items = { "Flyer", "Card" } }Steps
- Return
first: the first item ininput.items. - Add
count: how many items there are. - Add
withProof: a copy of the items with"Proof"added at the end. Leaveinput.itemsunchanged.
Show a hint
Copy with table.clone(input.items), then table.insert into the copy.