DarwinBotsManual
Open the app EspañolES

anglecmp

Compares two angles and gives the shortest difference between them, signed, between −628 and 628: how much and which way to turn.

Facts

Word
anglecmp
Family
Advanced
Integer stack
pops 2, pushes 1
What it does
Pops two angles a and b, in .aim units, and pushes a − b by the short way around: from −628 to 628.
Cost
Advanced command; debugint and debugbool are free
Runs
inside a gene: in the condition (cond) and in the body (start or else)

a b anglecmp leaves the difference a − b between two angles, but by the short way around: between −628 and 628 (half a turn in each direction). The angles are in the units of .aim, where 1256 is a full turn, and before being compared they are brought into that range, so 1300 and 44 are the same angle.

a b anglecmpResult
300 100200
100 300−200
100 1200157 (the short way)
0 628−628

A positive result means that a is to the left of b (counterclockwise). That is why target *.aim anglecmp is exactly how much to turn left with .aimsx to face the target; if it comes out negative, the turn goes the other way. This bot orients itself downward (942):

cond
start
  942 *.aim anglecmp .aimsx store
stop

In the first cycle *.aim still reads 0, so the bot overshoots; in the second it already corrects and ends up facing 942. To ask only whether it is already pointing roughly right, use the absolute value: 942 *.aim anglecmp abs 20 <.

angle gives the angle toward a point, and it is the natural companion of anglecmp.