← Back to course
review ✦ 50 Studs

Math and Strings

Do some math, then glue strings together with .. to build a message.

Numbers in Lua work exactly how you’d expect: +, -, *, /, and % for the remainder. No surprises there, you’ve done plenty of this already.

The piece worth a second look is the .. operator. Two dots. That’s how Lua glues strings together, which we call concatenation (fancy word, simple idea). It’s like snapping two Lego bricks end to end.

local coins = 25
print("You have " .. coins .. " coins")

See how a number slid right into the middle of a string? Lua quietly converts it to text when you concatenate. That trick is everywhere once you start building games, because almost every message on screen is part fixed text and part live value.

Now make it yours: add score and bonus, then print one clean message that includes the total. Try changing the starting numbers and watch the message update itself.

Output
Click Run to see your output.