Coding Project 9 — Names for Your Numbers
KIPR · Botball Explorer
Activity Sections

Introductory · SPIKE Coding Project 9

Names for Your Numbers

Your comments become real code. Change a number once, and the whole program changes with it.

Project
Coding Project 9
Strand
Coding
Phase
Make It Reliable
Time
One class period
What You Are Doing
Turning the numbers scattered through your programs into named s, then using that cleaner code to stack the red cubes.
Mission Anchor
Mission 5 — Top Shelf Delivery (base + bonus) — 20 points
What You Need
Before You Start
Project 8 — you need a working grab sequence and all seven numbers on your motor card.
Before you start: type your PIN in the box at the top of the page. Your teacher gave you this number. When you finish, press Download to save a local copy of your answers. This does not turn in your work automatically; give the downloaded file to your teacher.

Try It — Count the Damage

Open your Project 8 program — the big one with all four missions in it. Scroll through it slowly.

How many blocks contain each of these as a bare number?

Count
My arm’s “up” position
My arm’s “down” position
My claw’s “open” position
My claw’s “closed on a cube” position
My arm speed

Now break it

⚠ Your Teammate Rebuilt the Claw Last Night

It grips better now. But the closed position is different — it is 30 lower than it was.

Find every block that number lives in and change it. Time yourself.

QuestionAnswer
How long did it take?
How many blocks did you have to edit?
Are you certain you got them all?

That last question is the real problem. If you missed one, what would happen — and how would you find out?

This Gets Worse, Not Better

Your program is going to keep growing. By the time you are running a full match, that number could be in twenty blocks. There is a fix, it takes one block, and you are about to learn it.

Learn It — Give the Number a Name

A is a name that holds a value. You set it once at the top of your program, then use the name everywhere instead of the number.

Making one

Open the orange Variables category and press Make a Variable. Name it arm up. Two new things appear:

Code / partWhat it means
a round orange ovalThe variable itself. This oval is the name — and it fits into any white number hole in any block.
a “set … to” blockGives the name its value.

Where variables go

The set blocks go at the very top of the stack — right under the hat, above everything else. Not scattered through the middle of your program. One place, all together, where anyone can find them.

From card to code

You have been writing your positions on your Robot Card in name = number form since Project 7. There was a reason for that. Each line on the card becomes one variable and one set block:

Code / partWhat it means
card: up = 130Make a Variable named arm up  →  set arm up to 130 at the top of the stack.
card: closed = 55Make a Variable named claw closed  →  set claw closed to 55.

Then use the names

Here is the part that feels like magic the first time: drag the orange oval and drop it into the white number hole of any block.

Read both versions out loud. One is a list of numbers. The other tells you what the robot is doing.

Five Reasons This Is Worth the Trouble

  • You do not have to remember which number is up, down, open, or closed — the program remembers for you.
  • Your program is easier to read.
  • Your program is easier to debug.
  • Anyone on your team can work on it.
  • If a position changes, you change one set block.

Name things properly

Make it obvious: arm up, not thing2. A name nobody can decode is barely better than a bare number.

The Leftover-Oval Check

The Variables shelf lists every variable you have made. A variable sitting on the shelf that never got dropped into a single block usually means one thing: somewhere in your stack, a bare number is still hiding. When you finish converting a program, read it top to bottom hunting for naked numbers.

Variables can change

Most of your variables hold one value forever — up is always up. But a variable is called a variable because it can vary. Two ways to change one:

Change by is the shorthand for “take what it holds and add this.” You will meet the real use for it in Project 10, once you have a loop to put it in.

Do It — Clean It Up, Then Score

Step 1 — Convert one small program first

Open your Arm Wave program from Project 7. Make variables for the three positions, set them at the top, then drop the ovals into the position blocks in place of the numbers.

Run it. It should behave exactly as before.

If it behaves differently, you swapped two values. That is the most common mistake here.

Step 2 — Do the leftover-oval check on purpose

Make a variable called not used and never drop it into anything. Now look at your Variables shelf.

How would you spot, a week from now, that this variable never made it into the program?

Delete it, so the shelf only lists names that are really in use.

Step 3 — Convert your big Project 8 program

This is the real job. Make all your variables, set them at the top, then work down the stack replacing bare numbers with ovals.

VariableMy valueDone?
arm up
arm horizontal
arm down
claw open
claw closed
arm speed

Convert One Mission Section at a Time

Same rule as building it in the first place. Convert one section, run it, then move on. Converting all four at once and finding it broken tells you nothing about where.

Step 4 — Now do the claw change again

Same problem as Try It. Your claw’s closed position drops by 30. Change it.

QuestionAnswer
How long did it take this time?
How many places did you edit?

Compare those two numbers with the ones you wrote in Try It.

Step 5 — Try changing a variable while the program runs

Small experiment. Build this and watch the arm.

The arm moved in three hops instead of one jump. What would you have to do to make it move in thirty small hops?

Hold that thought. Project 10 gives you the tool that makes it three blocks instead of thirty.

Step 6 — Mission 5 — Top Shelf Delivery20 pts

Watch Mission 5 video

Base Mission

9 points Live judged

A Small Red Cube is the Large Red Cube.

Bonus Mission

11 points Live judged

Both Small Red Cubes are the Large Red Cube.

Scores

  • One Small Red Cube is the Large Red Cube.
  • One Small Red Cube is touching the upper surface of the Large Red Cube while supported by a robot.
  • One Small Red Cube is the Large Red Cube and later falls off.
  • Both Small Red Cubes are the Large Red Cube at the same time.

Does Not Score

  • A Small Red Cube touching only the side of the Large Red Cube.
  • A Small Red Cube hovering above the Large Red Cube without touching it.
  • Only one Small Red Cube is the Large Red Cube for the Bonus Mission.

This one asks your arm to reach higher than anything so far. The large red cube is the platform; the small ones go it.

Scores

  • One Small Red Cube is ON TOP OF the Large Red Cube.
  • A Small Red Cube touches the upper surface while supported by a robot.
  • A Small Red Cube is ON TOP OF, and later falls off.
  • Both Small Red Cubes are ON TOP OF at the same time.

Does Not Score

  • A Small Red Cube only the side of the Large Red Cube.
  • A Small Red Cube hovering above without .
  • Only one Small Red Cube up there, for the Bonus.

Live Judged Is On Your Side Here

Robot support is permitted, and the cubes do not have to stay up there. Once the judge has seen it, it counts — even if it falls a second later.

⚠ Check What Mission 2 Did to These Cubes

In Project 6 you pushed the Large Red Cube, its , and both Small Red Cubes off the black line. Those are the same cubes you need here. Where they ended up decides how hard this is — so plan the two missions together, not separately.

Where do your red cubes end up after your Mission 2 push? Does that help or hurt you here?

The bonus needs both cubes up there at the same time. Why does that make the second one harder than the first?

Step 7 — Run it five times

RunFirst cube on top?Both at once?Points
1
2
3
4
5

Score It — Checkpoint

My score

Mission partScored?Points
Mission 5 — Base (one small red cube on top)9
Mission 5 — Bonus (both small red cubes on top)11
My total20

Make the variable

For each card line, say what you would do in the app.

Card lineIn the app I would…
open = 145
down = 40
arm speed = 20

Read the blocks

Given set arm down to 40 at the top of a stack — what does each of these do?

BlockWhat it does
run C to position (arm down) degrees
change (arm down) by -50
set (arm down) to (arm up)

That last one is a legal block that does something you almost certainly do not want. Say what it actually does.

Can you do it again?

Think about it

Nothing your robot does changed in this project — it drives, grabs, and stacks exactly as it did before. So what actually got better?

Variables fixed the problem of one number appearing in many places. But your program still has the six-step grab sequence built out four separate times. Would variables fix that too? Why or why not?

Your teammate opens your program for the first time. Which version could they work on — the one from Project 8, or this one? What does that tell you about who you are really writing programs for?

Next

Your robot still cannot tell when it has arrived anywhere. It drives for a length of time and hopes.

In Project 10 — Feeling for Things, it gets its first sense: a switch that knows when it has touched something — and the loop that keeps checking.

Download saves a local copy of your answers. It does not turn in your work automatically; give the downloaded file to your teacher.

KIPR · Botball Explorer — Introductory Projects · © KISS Institute for Practical Robotics 1997–2026