'F' → Fullscreen
Copy template-console to 1-11-logic. Fill in the truth table on your sheet first, then write the twelve lines that check it:
print(true and true)print(true and false)print(false and true)print(false and false)Then the same four for or, and print(not true) and print(not false).
Ten lines, ten answers, and you should already know all of them. Mark any you got wrong.
Copy 1-09-bounce to 1-11-bounce. First reproduce the bug: set the starting x to 900 and run it. Nothing appears.
Now add four words:
function love.update(dt) x = x + speedX * dt
if x > 800 - radius and speedX > 0 then speedX = -speedX end
if x < radius and speedX < 0 then speedX = -speedX endendRun it again. The ball flies in from off-screen and bounces normally forever.
Put the starting x back to 100 and replace love.draw with a readout:
function love.draw() if x > 400 and speedX > 0 then love.graphics.setColor(0.2, 0.8, 0.3) else love.graphics.setColor(0.6, 0.6, 0.6) end love.graphics.circle("fill", x, y, radius)
love.graphics.setColor(1, 1, 1) love.graphics.setFont(font) love.graphics.print("x > 400 " .. tostring(x > 400), 40, 340) love.graphics.print("speedX > 0 " .. tostring(speedX > 0), 40, 380) love.graphics.print("both (and) " .. tostring(x > 400 and speedX > 0), 40, 430) love.graphics.print("either (or) " .. tostring(x > 400 or speedX > 0), 40, 470) love.graphics.print("not past middle " .. tostring(not (x > 400)), 40, 510)end

Watch it for a full round trip. Find the moment when the top two lines disagree, and write down what each of the bottom three says at that moment.
Change the color condition, and only that one:
if x > 400 or speedX > 0 thenThe ball is now green for three quarters of its round trip. Work out which quarter it is still gray for, and write down why.
or is a much weaker demand than and. Most of the time, one of two things is true.
Give the ball a speedY so it bounces around the whole window, then turn it a different color only when it is in the middle square — between 300 and 500 across and between 200 and 400 down.
That is four comparisons joined by three ands. Write it on your sheet before you type it.
Rewrite your middle-square condition so it says the same thing using not and or instead of and.
Test that both versions behave identically, then say which one you would rather read in six months.
Three words, in capitals, and they work exactly as they do in Lua.
if lives > 0 and score >= 100 then print("Next level")end
if lives == 0 or timeLeft == 0 then print("Game over")end
if not paused then print("Running")endIF(lives > 0 AND score ≥ 100){ DISPLAY("Next level")}
IF(lives = 0 OR timeLeft = 0){ DISPLAY("Game over")}
IF(NOT paused){ DISPLAY("Running")}| Meaning | Lua | Exam notation |
|---|---|---|
| Both | and | AND |
| Either | or | OR |
| The opposite | not | NOT |
The truth tables are identical, so anything you worked out today is true on the exam as well. The differences are all in the pieces you already know — = for equality and ≥ for greater-or-equal inside the conditions.
lives == 0 or timeLeft == 0 becomes lives = 0 OR timeLeft = 0. Two operators change in one line, and the one people miss is the second.1-11-bounce recovers from a start position of 900and is true but or is not — and when it is the other way roundAnswer the following questions before submitting your work.
if. Explain what the old condition was actually asking, what the new one asks, and why only the second one works.and for or in one line changed almost nothing on screen for most of the trip. Explain why a wrong logical operator is harder to notice than a wrong comparison.and, and one that needs or. Say how you can tell them apart from the wording.Submit the required files to the appropriate dropbox.