Menu
Coddy logo textTech

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    250

When 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    75
challenge icon

Challenge

Easy

Create 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    250

Lua automatically adds tab spacing between comma-separated values:

level = 5
health = 100
mana = 75
print("Stats:", level, health, mana)  -- Output: Stats:    5    100    75

Try it yourself

-- TODO: Write your code here
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals