DarwinBotsManual
Open the app EspañolES

.xpos

The bot's horizontal position in the world: 0 at the left edge and growing toward the right.

Facts

Address
219
Name
.xpos
Kind
Sense: the engine writes it for the DNA to read
Group
Position and surroundings
Written by
The engine, in the actions phase of every cycle: the distance from the bot's center to the left edge. You read it in the next cycle.
Cleared
Nobody; the engine rewrites it every cycle.
Range
0 to 31999; past 32000 it starts over from 0. The settings can divide it by a factor.
Mutations
picked as a read (*)

.xpos is the horizontal coordinate of the bot's center, measured from the left edge of the world, in the same units as the field size. Its partner is .depth, the vertical one. The engine publishes it at the end of each cycle; in the first cycle of life it is 0.

A memory cell holds at most 32000, so in a world wider than that the value starts again from 0. The simulation can also be configured to divide the coordinates by a factor before publishing them.

It's useful for staying in one zone of the map, for a multibot to know where each cell is or, together with .refxpos, to tell whether what it sees is to the left or to the right. This bot heads back toward the left half of a world 4000 wide when it goes past the middle:

cond
*.xpos 2000 >
start
628 .setaim store
20 .up store
stop

The 628 points to the left of the screen (see .aim). Watch out for inertia: when it is back below 2000 it stops pushing, but without friction it keeps sliding to the opposite wall. To stay in the zone you have to brake, as shown in .velup.