'F' → Fullscreen
Copy template-game and rename the copy 1-03-circle. Replace what is inside love.draw so the file looks like this:
local circleX = 400local circleY = 300local radius = 40
function love.draw() love.graphics.circle("fill", circleX, circleY, radius)endRun it. A white circle in the middle. Now change one line and run again:
local circleX = 150Then try changing radius, and then circleY. Run after each one.
love.draw, not inside it. Keep love.keypressed at the bottom of the file, unchanged, so Escape still closes the window.Copy your 1-02-signal folder and rename the copy 1-03-signal. Add four variables above love.draw:
local lightX = 400local lightY = 190local radius = 35local gap = 110Now replace the numbers inside the box with those names. The rectangle needs arithmetic, because it is placed by its corner and the lights are placed by their centers:
local lightX = 400local lightY = 190local radius = 35local gap = 110
function love.draw() love.graphics.setColor(0.6, 0.6, 0.6) love.graphics.rectangle("fill", lightX - 50, lightY - 60, 100, 340)
love.graphics.setColor(0.9, 0.2, 0.2) love.graphics.circle("fill", lightX, lightY, radius)
love.graphics.setColor(0.9, 0.8, 0.2) love.graphics.circle("fill", lightX, lightY + gap, radius)
love.graphics.setColor(0.2, 0.8, 0.3) love.graphics.circle("fill", lightX, lightY + gap + gap, radius)endRun it. The picture should look exactly like it did last session. Nothing changed on screen, and that is how you know you did it right.
Change two lines, and only those two:
local lightX = 200local lightY = 120
Four shapes moved, and you touched two numbers. Now set gap to 80 and radius to 25 and see what happens.
Put lightX and lightY back to 400 and 190 before you submit, or leave the signal wherever you like it — but write down which you chose.
Change one variable name in the red light's line so it no longer matches the one at the top of the file — a lower case x instead of a capital one:
love.graphics.setColor(0.9, 0.2, 0.2) love.graphics.circle("fill", lightx, lightY, radius)The window turns blue and shows this. Press Escape to dismiss it:
Error: main.lua:11: bad argument #2 to 'circle' (number expected, got nil)Lua did not say "there is no such variable." It said the circle got nil where it wanted a number. Write down what you think nil means, then fix the spelling.
A name you never made is not an error in Lua. It is a name holding nothing, and you find out later, somewhere else.
Copy your 1-02-scene from last session to 1-03-scene and rebuild it so that one variable moves the entire drawing and one more variable changes its size. Every shape has to be positioned from those two.
The exam does not use Lua. It uses its own written notation, and you get a booklet of it on exam day. Assignment is the first thing on that sheet.
local lightX = 400local gap = 110
lightX = lightX + 50print(lightX)lightX ← 400gap ← 110
lightX ← lightX + 50DISPLAY(lightX)| Lua | Exam notation | |
|---|---|---|
| Make a variable | local lightX = 400 | lightX ← 400 |
| Change it | lightX = lightX + 50 | lightX ← lightX + 50 |
| Show it | print(lightX) | DISPLAY(lightX) |
There is no local. The arrow makes the variable the first time you use it, and changes it every time after.
= means "is equal to". It is a question, not an instruction — the thing Lua writes as ==. Assignment is always the arrow, and comparison is always =. They never overlap, so a line with an arrow in it is always storing something.You will meet = as a comparison properly at session 8. For now, notice that the exam kept them apart and Lua did not.
1-03-circle draws one circle from three variables1-03-signal positions every shape from a variable — the only raw numbers left in love.draw are colors, the rectangle's width and height, and the two offsetslightX alone moves all four shapesAnswer the following questions before submitting your work.
score = score + 10 would be false in math class. Explain what it means in a program, in your own words, and say what score holds afterward if it held 40 before.nil instead of about spelling. Say why you think Lua reported it that way, and where the mistake actually was.Submit the required files to the appropriate dropbox.