Does my code work in metres or feet?
Setting a program's units
The units badge in Brain code's code bar, next to Save, shows the program's units: metric or imperial. Click it to switch. It adds or changes the units line at the top of your program:
# units: imperial
from bot import Chassis, Rangefinder, wait
chassis = Chassis(0)
rangefinder = Rangefinder(3)
while True:
rangefinder.bearing = chassis.heading
# In imperial the range is in feet: slow down 15 ft (about 4.6 m) out.
chassis.forward = 0.3 if rangefinder.hit and rangefinder.range < 15 else 1
wait()
The line must be a comment of its own among the program's first 20 lines, written the way your language writes comments: # units: imperial in Python, // units: imperial in JavaScript, C++, Java and C#, -- units: imperial in Lua, ' units: imperial in BASIC, ; units: imperial in assembly. A Blocks program keeps its units in its workspace; use the badge.
A new blank program starts in the units you've chosen to see values in. The house bots are written in metric.
What changes, and what doesn't
Converted (metres become feet, m² becomes ft²):
- Positions from a GPS or radio (
gps.read(),radio.read(),radio.teammate()), and from the other parts that report positions. - Distances, such as
rangefinder.range, a hopper's hop distance and a jet pack's altitude. - Points and lengths you send, such as a drone's or gunship's target point.
Not converted:
- Angles and bearings (degrees), throttle and turn rate (−1 to 1), hull points, ticks, seconds, counts and percentages.
- The numbers in your own code. If you switch a program's units, its constants stay as they were. After you click the badge, Brain code marks the lines whose numbers may be lengths so you can check them.
- Radio messages and the notepad. They're your team's own data, passed on exactly as sent. If one teammate's program is metric and another's imperial, agree on one unit for what they share.
Reading the Reference in feet
When a program is imperial, the Reference in Brain code shows values in feet too. Its examples are still written in metric, so their numbers are metres.
Under the hood
The game itself works in metric. It converts lengths and areas as they pass between the game and your program, using the units your program says it's written in. Which units you see values in elsewhere on the site is a separate setting.