Printing Multiple Values
Part of the Fundamentals section of Coddy's Lua journey — lesson 28 of 90.
Sometimes you need to display multiple pieces of information on the same line. Instead of using separate print() calls, Lua allows you to print multiple values with a single print() statement by separating them with commas.
name = "Alex"
score = 250
print(name, score) -- Output: Alex 250When you separate values with commas inside print(), Lua automatically adds a tab space between each item. This creates clean, organized output without needing to manually format the spacing.
level = 5
health = 100
mana = 75
print("Stats:", level, health, mana) -- Output: Stats: 5 100 75Challenge
EasyCreate variables for a player's game statistics and display them together on a single line. Create a variable called playerName and assign it the value "Phoenix". Create a variable called currentScore and assign it the value 2850. Use a single print() statement to display both the player's name and score on the same line, separated by Lua's automatic tab spacing.
Cheat sheet
To print multiple values on the same line, separate them with commas inside print():
name = "Alex"
score = 250
print(name, score) -- Output: Alex 250Lua automatically adds tab spacing between comma-separated values:
level = 5
health = 100
mana = 75
print("Stats:", level, health, mana) -- Output: Stats: 5 100 75Try 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