🎓 A1Learner
🔍
0 of 47 lessons completed

Lua Get Started

Running a script means Lua reads a file and carries out its lines one by one. In this course, every script is saved in a file named main.lua.

A complete main.lua file

This one line is the whole file. Saving it as main.lua and running it prints the line.

print("My first Lua script")

Lines run in file order

Three print lines sit in the file from top to bottom. The output keeps the same order, line for line.

print("Write the script")
print("Save the file")
print("Run the file")

print shows what the script did

A print line can show a label and a value together. Lua splits the two with a tab.

print("Files checked", 3)

Example

print("First Script Checklist")
print("File saved as main.lua")
print("Run command typed")
print("Output seen")

Key points

  • File name: every script in this course is saved as main.lua.
  • Run command: typing lua main.lua tells Lua to run that file.
  • Order: Lua runs the lines of a script from top to bottom.
  • print: print shows the results of a script on the screen.
  • Fresh run: editing the file and running it again shows the new results.
  • Result: the printed lines are how you check what a script did.

In this example, the whole program is saved as main.lua and run with lua main.lua. The first print shows the title. The next two prints list steps from the checklist. The last print shows the final step.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

Which command runs the script saved as main.lua?