Activities 1.1 – 1.6. Use this to review, or to fill in something you missed.
A program is a list of instructions carried out in order, and the computer does exactly what the list says. You copy a template folder for every new program rather than editing the original, and you never edit conf.lua.
printlove.draw is called by the engine about sixty times a second. Coordinates start at the top left and y grows downward. Rectangles are placed by their top left corner; circles by their center.
(0, 0) is the top left of the window; the window is 800 by 600.love.graphics.rectanglelove.graphics.circlelove.graphics.setColorThe 0-to-255 mistake is silent. Values above 1 are clamped to 1, so a color meant to be gray comes out white and everything drawn after it does too.
A variable is a name holding a value. = is an instruction, not a claim: work out the right side, then put the answer in the name on the left. That is why score = score + 10 makes sense.
local= in Lua and ← on the exam.local.io.read() always hands back a string, whatever the person typed. With 16 typed at a prompt and stored in age:
| Expression | What happens |
|---|---|
age * 2 | 32 — it silently works |
age == 16 | false — it silently lies |
age > 10 | an error — it crashes |
The fix is tonumber at the moment you collect the value. The silent lie is the dangerous one, because nothing tells you.
io.writeio.readtonumbernil if it cannot.Normal order of operations, in Lua and on the exam. / never truncates — 17 / 5 is 3.4, not 3.
%17 % 5 is 2. Written MOD on the exam, with the same precedence as * and /.math.floor* and / before + and -. Parentheses beat everything... joins two pieces of text. Not the same as adding.| Lua | Exam notation | |
|---|---|---|
| Make a variable | local x = 400 | x ← 400 |
| Change it | x = x + 50 | x ← x + 50 |
| Show a value | print(x) | DISPLAY(x) |
| Read a value | io.read() | INPUT() |
| Remainder | a % b | a MOD b |
Two things to remember about DISPLAY: it is how the exam prints, and it puts a space after what it shows. TwoDISPLAY calls in a row give you space-separated output on one line, not two lines.
There is no local on the exam. The arrow makes the variable the first time and changes it every time after.