dist
Gives the straight-line distance from the bot to a point x y.
Facts
- Word
dist- Family
- Advanced
- Integer stack
- pops 2, pushes 1
- What it does
- Pops a point (x below, y on top) and pushes the distance from the bot to it, in the real size of the world. It is capped at 2 billion.
- Cost
- Advanced command; debugint and debugbool are free
- Runs
- inside a gene: in the condition (cond) and in the body (start or else)
x y dist pops a point (the x below, the y on top) and pushes the distance from the bot to it. *.refxpos *.refypos dist is the distance to whatever it is looking at; with angle on the same point you also know which way it lies.
This bot notes where it was at the start (.xpos and .ypos in cells 50 and 51) and, every time it moves more than 300 away from that place, it aims back toward it:
cond
*.robage 1 =
start
*.xpos 50 store
*.ypos 51 store
stop
cond
*.robage 1 >
*50 *51 dist 300 >
start
*50 *51 angle .setaim store
stop
cond
start
10 .up store
stopThe position is noted with .robage at 1 and not at 0 because in the first cycle *.xpos is still 0.