Lua Output
Output is what a script shows on the screen. The print command is how a Lua script makes output.
Tabs split the values in one print
One print shows four values on a single line. A tab sits between each pair of values.
print("Lives", 3, "Level", 2)An empty print leaves a blank line
The middle print has nothing to show. It still finishes a line, which leaves the blank line in the output.
print("First section")
print()
print("Second section")Booleans print as words
print shows the boolean values true and false as words. The output is the two words, one per line.
print(true)
print(false)Example
print("Player Board")
print("Name", "Rin")
print("Score", 75)
print()
print("Game Board")
print("Level", 5)
print("Started", true)Key points
- Tabs: print splits several values on one line with tabs.
- Empty line: print() with nothing to show prints an empty line.
- Numbers: print shows a number as plain digits.
- Booleans: print shows true and false as words.
- New line: each print call finishes its line, so the next print starts below it.
In this example, the first three prints build the player section, with labels and values split by tabs. The empty print then leaves a blank line. The last three prints build the game section below it.
Note
print uses tabs for spacing, and lining values up in neat columns is a job for a later lesson.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does a print() call with nothing inside the brackets do?