What is a Table?
Part of the Fundamentals section of Coddy's Lua journey — lesson 56 of 90.
The table. Tables are Lua's single built-in data structure, but don't let that simplicity fool you - they're incredibly powerful and versatile.
Think of a table as a container that can hold multiple pieces of information. Unlike the simple variables you've worked with so far (which store just one value), a table can store many values in an organized way.
Tables can be used in different ways depending on what you need. In this chapter, we'll focus on using tables as lists - ordered collections of items where you can store things like a shopping list, player scores, or inventory items.
-- A simple list of player names
players = {"Alice", "Bob", "Charlie"}
-- A list of scores
scores = {100, 85, 92, 78}Cheat sheet
Tables are Lua's single built-in data structure that can hold multiple pieces of information. They can be used as lists - ordered collections of items.
Create a table using curly braces {} with comma-separated values:
-- A simple list of player names
players = {"Alice", "Bob", "Charlie"}
-- A list of scores
scores = {100, 85, 92, 78}Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators 2 Relational & Logic
Equality OperatorsRelational OperatorsThe 'and' OperatorThe 'or' OperatorThe 'not' OperatorShort-Circuit EvaluationTruthy and Falsy ValuesRecap - Simple Logic7Basic Conditional Logic
The if-then StatementThe if-then-else StatementThe elseif StatementRecap - Treasure Chest10Tables Part 1: List-Style
What is a Table?Creating a TableAccessing Elements by IndexModifying Elements by IndexThe Length Operator '#'table.insert()table.remove()Recap - Manage Party Members2Variables and Data Types
What is a Variable?NumbersStringsBooleansThe Value 'nil'The type() FunctionNaming ConventionsRecap - Character Profile5Basic Output
Printing LiteralsPrinting VariablesPrinting Multiple ValuesCombining Strings & VariablesThe tostring() FunctionInputCastRecap - Status ReportRecap - Till 1208String Manipulation Basics
string.len()string.upper & string.lowerstring.sub()string.rep()string.find()Recap - Format Username3Operators 1 Arithmetic & Conc
Arithmetic OperatorsModulo OperatorExponentiation OperatorString ConcatenationOperator PrecedenceRecap - Simple Calculations6Project: Character Stats Disp
Welcome MessageDeclare Character Stats9Functions Basics
Declaring a FunctionCalling a FunctionFunctions with ParametersFunctions with Multiple ParamsThe 'return' StatementRecap - Area Calculator