Home / Commodore 64 / Phase 0 / Lesson 3
Lesson 3 of 64

Decisions, Decisions

What you'll learn:

  • Use `IF...THEN` to branch based on comparisons.
  • Test numbers and strings with equality and inequality operators.
  • Pair `IF` with keyboard input and randomness to create interactivity.
5% Complete

Lesson 3 – Decisions, Decisions

Games react. They cheer, warn, or punish depending on what the player does. In BASIC, that power comes from IF...THEN. Today you’ll teach the C64 to choose, nudging it from obedient typist to playful partner.

[📷 suggested: screenshot of a simple prompt asking “DO YOU PRESS THE RED BUTTON?”]


The One-Minute Tour

  • IF checks whether a condition is true.
  • Comparisons use operators like =, <>, <, >.
  • THEN tells BASIC what to do when the condition passes; otherwise it skips ahead.

Example Program

NEW
10 PRINT "WHAT IS 2+2?"
20 INPUT A
30 IF A=4 THEN PRINT "CORRECT!"
40 IF A<>4 THEN PRINT "NOT QUITE."

Sample run:

WHAT IS 2+2?
?4
CORRECT!
READY.

Line 30 only fires when the answer equals 4.
Line 40 catches every other value. Together they give instant feedback without extra branching tricks.

Tip: When you use INPUT, BASIC automatically prints a ? prompt. Press RETURN after typing your answer.


Experiment Section

  • Replace 4 with another solution and re-run.
  • Swap the messages on lines 30 and 40 to see how logic flips.
  • Add a new branch: 50 IF A>10 THEN PRINT "SHOW-OFF!".
  • Use IF A=4 THEN GOTO 100 to jump ahead when the player succeeds (we’ll refine that pattern later).

[🎥 suggested: clip entering different answers and showing the alternate lines lighting up]


Concept Expansion

There’s more to interactivity than INPUT. You can respond to single key presses with GET and create branching stories with multiple IFs. As lessons progress you’ll combine decisions with loops so the machine keeps asking questions or reacting inside a game loop.


Game Integration

  • Menus: IF CHOICE$="S" THEN START_GAME.
  • Collisions: IF PLAYERX=ENEMYX AND PLAYERY=ENEMYY THEN GOSUB 500.
  • Difficulty: IF SCORE>20 THEN SPEED=2 to ramp up tension.

Branching with Single Keys

Sometimes you want instant reactions without waiting for RETURN. Combine GET with IF to build a quick decision point:

40 PRINT "PRESS Y TO OPEN THE DOOR OR N TO RUN AWAY"
50 GET K$: IF K$="" THEN 50
60 IF K$="Y" THEN PRINT "THE DOOR CREAKS OPEN..."
70 IF K$="N" THEN PRINT "YOU DASH BACK INTO THE HALL."
80 IF K$<>"Y" AND K$<>"N" THEN PRINT "CONFUSED, YOU STAY PUT." : GOTO 50

Add a surprise by seeding the random generator and checking a random value:

90 RND(-TI)
100 IF RND(1)<0.2 THEN PRINT "A MONSTER APPEARS!"

Now each choice can branch further depending on luck.


From the Vault

  • Commodore 64 — peek at how the BASIC interpreter scans each line in order, making branching feel instant.

Quick Reference

REM Decision basics
IF <condition> THEN <statement>
IF X=10 THEN PRINT "HIT"
IF X<>10 THEN PRINT "MISS"
IF NAME$="JANE" THEN GOSUB 500
  • Conditions can compare numbers or strings.
  • <> means “not equal.”
  • You can chain multiple IFs to cover every possibility.
  • C64 BASIC stores input in uppercase by default; compare with uppercase strings ("Y", not "y").

What You’ve Learnt

  • IF...THEN lets BASIC react instead of just recite.
  • Comparisons handle both numbers (A=4) and strings (A$="Y").
  • Multiple IFs create branching outcomes for the same input.
  • Decisions are the fuel for menus, collisions, and story beats.

Next lesson: Counting on You — introduce variables and arithmetic to track scores, lives, and more.