Menu
Coddy logo textTech

Printing Variables

Part of the Fundamentals section of Coddy's Lua journey — lesson 27 of 90.

The values stored in variables. When you pass a variable name to print(), it outputs whatever value is currently stored in that variable.

Here's how to print a variable's value:

playerName = "Alex"
print(playerName)  -- Output: Alex

score = 150
print(score)       -- Output: 150

Notice that when printing variables, you don't use quotes around the variable name. The print() function automatically retrieves the current value from the variable and displays it. This works with any data type - strings, numbers, booleans, or even nil.

isReady = true
print(isReady)     -- Output: true

emptyValue = nil
print(emptyValue)  -- Output: nil
challenge icon

Challenge

Easy

Create a variable called characterName and assign it the value "Warrior". Create another variable called currentLevel and assign it the value 12. Print both variables to display the character's name and level.

Cheat sheet

To print a variable's value, pass the variable name to print() without quotes:

playerName = "Alex"
print(playerName)  -- Output: Alex

score = 150
print(score)       -- Output: 150

This works with any data type:

isReady = true
print(isReady)     -- Output: true

emptyValue = nil
print(emptyValue)  -- Output: nil

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