Lesson 1 of 10
Your first script
- 8 min
- 5 checks
- 3 hints
- Go to task
Goal
The local keyword, print and the .. operator for joining strings
Explanation
Lua was designed to be embedded inside bigger programs, which is why you find it in game engines and game servers: Roblox and FiveM scripts, World of Warcraft add-ons and LÖVE games are all written in Lua or a language close to it.
You define a variable with the local keyword, like this: local name = "Layan". If you leave out local, the variable becomes global and every script in the game can see it, which causes hard-to-track bugs when two scripts use the same name.
You join strings with two dots .., not with +, as in "Level " .. level, because + between two strings tries to convert them to numbers and fails.
Your task
Use local to define two variables: name holding a string and level holding an integer. Then print a single line that contains both, joined with ...
Checks
5 checks- name is a non-empty string
- level is an integer
- Both variables are defined with local
- The name was printed
- The level was printed on the same line