Languages, name and versions
Five languages, the robot's name and the versions of its code.
Name and language
A robot can be written in JavaScript, TypeScript, Python, Ruby or Lua. The robot’s name is the class name, and the language comes from how the class extends Robot:
class MyRobot extends Robot {
run() {
while (true) { const state = this.scan(); }
}
}// @language typescript
class MyRobot extends Robot {
run(): void {
while (true) { const state: State = this.scan(); }
}
}class MyRobot(Robot):
def run(self):
while True:
state = self.scan()class MyRobot < Robot
def run
loop do
state = scan
end
end
endMyRobot = Robot:extend()
function MyRobot:run()
while true do
local state = self:scan()
end
endNames in each language
Each language has its own way of writing names, in the commands and in the state:
- JavaScript and TypeScript: camelCase, with
this.(this.turnRadar(1),state.me.distanceToEdge). - Python, Ruby and Lua: snake_case (
self.turn_radar(1),state.me.distance_to_edge). In Rubyselfis optional; in Lua, useself:.
Used another language’s name? The battle error tells you the right one, for example: turnRadar is not a Python command: use turn_radar.
Versions
Every time you save different code, the robot gets a new version (v1, v2…). A battle uses the version chosen when joining: the latest by default, or an earlier one. Code and build stay fixed in that battle; saving later only affects the next ones.
In My robot → History, open an earlier version in the editor. Saving a change creates a new version, without deleting the old ones.