Two things: VS Code and LÖVE. On a lab computer both are already installed and you can skip straight to the next section.
LÖVE is doing two jobs at once. It runs your Lua code, and it is also the drawing library this course uses. That is why there is nothing else to install — no separate Lua, no package manager, and nothing in this course needs an internet connection once you have the workspace folder.
Working on your own computer? Install VS Code from code.visualstudio.com and LÖVE from love2d.org. Get LÖVE 11.5 if you are offered a choice — error messages change wording between versions, and that is the one this course is written against. On a Mac, install it by running brew install --cask love if you can, because that puts LÖVE somewhere the Run button can find it.
lua-workspace folder itself. Not the folder above it, and not a file inside it.If you missed the extension prompt, open the Extensions panel and type @recommended in its search box. The same three will be listed.
Inside the workspace there are two folders whose names start with template-. You never work in them. You copy one, rename the copy, and work in that. Every activity in this course starts the same way.
template-console and choose Copy, then Paste. You get a second folder.1-01-first-run.main.lua inside it. It already contains this:io.write("What is your name? ")local name = io.read()print("Nice to meet you " .. name)Press the Run button — the ▷ at the top right. A terminal panel opens at the bottom, asks for your name, and waits. Type it and press Enter:
What is your name? Ada [Enter]Nice to meet you AdaThat is the whole loop for this course: copy a template, write, press Run, read what came out.
conf.lua. It is the other file in the folder, and it is what makes the Run button behave properly — it decides whether a window opens and makes sure your output appears the moment it is printed. Everything you write goes in main.lua.template-console — a program that prints text and reads what you type. No window opens. main.lua is ordinary Lua: it runs from the top of the file to the bottom and then the program ends.
template-game — a program that opens a window and draws in it. Here main.lua is a set of functions that LÖVE calls for you, over and over, many times a second:
function love.draw() love.graphics.print("Hello World!", 400, 300)end
function love.keypressed(key) if key == "escape" then love.event.quit() endendYou did not write the code that calls those. LÖVE calls love.draw every frame, and love.keypressed whenever a key goes down. Think of them as boxes the engine opens: you decide what goes inside, and something else decides when to look. We come back to what function really means later in the quarter, and by then you will have been writing them for weeks.
Run runs the folder, not the file. It looks at whichever file you have open, finds the folder that file is sitting in, and runs the main.lua there.
Most of the time this is exactly what you want: you can have any file in the activity folder open, press Run, and the activity runs. Two rules keep it that way.
main.lua and conf.lua. That is what copying a template gives you.One folder per activity, sitting next to the two templates, named the way the activity page tells you. Nothing else to organize.
Read the message before you change anything. Where the message appears depends on which template you copied, so that is the first thing to notice.
A console program that asks for something that is not there:
local scores = {90, 85, 78}print("Third score: " .. scores[3])print("Fourth score: " .. scores[4])Third score: 78
Error: main.lua:3: attempt to concatenate a nil value
main.lua:3: in main chunkNotice that the first line printed. The program ran, got to line 3, and stopped there. A list with three things in it has no third-and-then-some — there is no scores[4], so there was nothing to join onto the text.
A missing end:
local x = 5if x > 3 then print("big")Error: Syntax error: main.lua:4: 'end' expected (to close 'if' at line 2) near '<eof>'Nothing printed, because the program never started. Read this one carefully — it names two lines. Line 4 is where Lua gave up looking, and line 2 is where the thing it was looking for should have been closed. The mistake is almost always at the second number, not the first.
When a program that draws hits an error, LÖVE takes over the window and fills it with a blue screen showing what went wrong and the line it happened on. Read it, press Escape to close it, fix the line, run it again.
The tell is whether anything happened first. Output and then a stop means the program ran and hit something part way through. Nothing at all means it never got started, and that is nearly always a missing end or an unclosed quote.
@recommended, and install all three.lovec not being recognizedlua-workspace itself, not at the folder containing it, or the settings that make any of this work are not loaded. Close it and reopen with File > Open Folder.