Learn Lua · Basics · Lesson 1 of 4

Values and variables

So far your code has used values written into it. A real script works on data that CoCoCo hands it, called input. You read it at the top with local input = ...: the three dots stand for whatever CoCoCo passes in. Then you use its fields with a dot, as in input.name.

Each time your code is checked, input holds different values, so work from the fields rather than from the example values. In these lessons the line above, type Input = { … }, lists the fields input has so the editor can suggest them. You'll learn to write types like this later in the course.

A table holds several named values at once. You've returned one already: you write it with braces, and read a field with a dot:

LUA
local order = { customer = "Ada", total = 7.5 }
order.customer  --> "Ada"

What 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.

LUA
input = { name = "Ada", price = 2.5, quantity = 3 }

Steps

  1. Return a table whose customer is the customer's name, from input.name.
  2. Add total: the price times the quantity, from input.price and input.quantity.
  3. Add paid, set to false.
Show a hint

Build the table in the return line: return { customer = input.name, … }. Separate the fields with commas.