Can I use libraries, imports, strings or random numbers in my bot's code?
What each language imports
| Language | What you write |
|---|---|
| Python | from bot import Chassis, Scanner, Laser, wait (or from bot import *) |
| JavaScript | import { Chassis, Scanner, Laser, wait } from "bot"; |
| C++ | #include <Bot.h> |
| Java | import bot.*; |
| C# | using BotArena; |
| Lua | nothing: the parts, cpu and wait are built in |
| BASIC, Blocks | nothing: the parts are already there |
Anything else is a compile error. For example, import math in Python gives write from bot import Chassis, Scanner, Laser, wait (other modules aren't available), and #include <Servo.h> in C++ gives only <Bot.h> can be included here, not <Servo.h>.
Why no strings?
The bot CPU has no text output, so there's nothing to print to. Use log() instead: each {} in its text shows the next value.
log("fire @ {}", b)
Logs are free. They cost no cycles, don't count against your ROM, and never change what your bot does, so leave in as many as you like.
When you need a character's code, for example to write on the team notepad, each language has a way to get one at compile time: ord("A") in Python, "A".charCodeAt(0) in JavaScript, 'A' in C++, Java and C#, string.byte("A") in Lua, ASC("A") in BASIC, and the code of block in Blocks.
Why no random numbers?
Matches are deterministic: the same programs on the same match always play exactly the same way. That's what makes replays and fair ratings work. If you want your bot to vary what it does, base it on what it senses, or on cpu.tick, the ticks since the match started.
Writing your own helpers
In the text languages you can write your own functions (in BASIC, subroutines with GOSUB; in assembly, CALL). Blocks has no custom blocks. A common pattern is a small helper you reuse, such as one that wraps an angle into −180..180. If you want the same helper in several bots, copy it into each program: every program is one file.