Variables
A variable is a named "box" that stores a number or text your program can read and change at any time. Created in the Variables category (red).
Create and use
Click "Make a Variable" in the Variables category, name it (say speed), and you get three blocks:
set [speed] to [50]
change [speed] by [10]
(speed) ← round reporter, drop into any input slotUse variables instead of hard-coded numbers:
when program starts
set [followSpeed] to [35]
set movement speed (followSpeed) %Change it in one place, every user of it updates.
The counter pattern
"change x by 1" + a loop = counting:
set [laps] to [0]
repeat until <(laps) = [3]>
move [forward] for [2] rotations
move [steering 100] for [340] degrees
change [laps] by [1]
write (laps)Variables as calibration parameters
The most valuable FLL habit: gather every number that needs field tuning at the top of the program.
when program starts
set [blackThreshold] to [30]
set [whiteThreshold] to [75]
set [followSpeed] to [30]
... everything below references these threeWhen venue lighting changes, you edit three numbers at the top instead of hunting through the whole program.
Lists
The Variables category can also create lists - ordered sequences of values:
add [2] to [route]
add [-1] to [route]
(item [1] of [route])
(length of [route])Advanced idea: encode a route as a list (positive = drive rotations, negative = turn) and execute it in a loop. Most teams do fine without lists - just know the tool exists.
Show values: essential debugging
write (color sensor [C] reflected light)Display a live sensor reading on the light matrix and read values right on the mat - threshold calibration depends on this.
Exercises
- Create a
speedvariable; left hub button subtracts 10, right adds 10, and the matrix shows the value (three parallel stacks). - Use the counter pattern to drive a square (4x "straight + right turn 90°").
Basics complete. Next up: give the robot senses in the Sensors section.