Numbers
Part of the Fundamentals section of Coddy's Lua journey — lesson 5 of 90.
In Lua, working with numbers is beautifully simple. Unlike some programming languages that have separate types for whole numbers and decimals, Lua uses a single number type for everything numeric. This means you can store both whole numbers (like 42) and decimal numbers (like 3.14) in the same way.
Here's how you create variables with different types of numbers:
playerScore = 1500
gameVersion = 2.1
temperature = -10Whether you're working with a player's score of 1500 points, a game version like 2.1, or even negative numbers like -10 degrees, Lua handles them all as the same number type.
Challenge
EasyCreate two variables to store numeric information for a game character. First, create a variable called playerScore and assign it the value 2500. Then, create a variable called gameVersion and assign it the value 1.3. Finally, print both variables to display their values.
Cheat sheet
Lua uses a single number type for all numeric values, including whole numbers and decimals:
playerScore = 1500
gameVersion = 2.1
temperature = -10Both positive and negative numbers, as well as decimals, are handled as the same number type.
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