Booleans
Part of the Fundamentals section of Coddy's Lua journey — lesson 7 of 90.
A boolean is a data type that can only hold one of two values: true or false.
Think of booleans as simple yes/no answers or on/off switches. They're perfect for representing states like whether a player is alive, if a door is locked, or if a game is over.
Creating boolean variables in Lua is straightforward:
isReady = true
gameOver = falseNotice that true and false don't need quotes around them - they're special keywords in Lua, not strings.
Challenge
EasyCreate a variable named isReady and assign it the boolean value true. Then print the value of this variable.
Cheat sheet
A boolean is a data type that can only hold one of two values: true or false.
Creating boolean variables in Lua:
isReady = true
gameOver = falseNote that true and false are special keywords in Lua and don't need quotes around them.
Try it yourself
-- TODO: Write your code hereThis 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 Chest2Variables 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