thebotslam

Why does my bot just sit there and do nothing?

Work through these in order.

1. Does it compile?

Errors are listed under the editor in Brain code, and their line numbers are marked in the gutter. A program with errors can't run.

2. Does the loop call wait()?

Commands only go out at wait(). A loop without it uses up every tick's cycles and never sends a thing:

while True:
    chassis.forward = 1
    wait()  # without this, the bot never moves

Commands set after the last wait() before a program ends never go out either.

3. Are the parts on the right channels?

A part whose channel holds nothing, or another type of part, reads 0 and ignores commands. Brain code warns about it, for example "The program connects a WPN-1 on channel 3, but this machine has nothing there". Open the Machine section under the editor to see each part's real channel, and fix the number in your code (or the design in the Factory).

4. Is a command actually set?

5. Is it crashing?

An index outside a list, or the stack running out (say, a function that calls itself forever), is a fault. The CPU stalls for a second, then restarts the program from the top. A bot that keeps faulting looks stuck. Log cpu.faults to find out:

if cpu.faults > 0:
    log("rebooted {} times", cpu.faults)

6. Something else stopped it

In a match, other things can stop a bot that's working fine: an enemy's contact EMP knocks a bot out for a minute, and while your own EMP charges, your sensors read 0.

Use the log

log() costs no cycles and never changes the match, so log freely. Log what the bot sees and decides, start a match with Run test in Brain code's Test arena, and read each bot's log as the match plays in the Arena:

log("hull {} scan {|}{|}{|}{|}", chassis.hull, scanner.ping(0), scanner.ping(1), scanner.ping(2), scanner.ping(3))

{} shows a number; {|} shows | for true and . for false.