DarwinBotsManual
Open the app EspañolES

The .txt format

What a bot's .txt file looks like on the inside: lines, comments, the '# header, the encoding, and what changes when the engine exports it.

All bots are saved as text files with a .txt extension: the ones in the Bestiary, the ones you write yourself and the ones the app exports from a simulation. This page covers how the loader reads that file, line by line, and what the engine writes when it sends it back out. The shape of the DNA itself (genes, tokens, def) is in The structure of a bot; the app's other formats, such as saved simulations, are in File formats.

Lines

The loader reads the file one line at a time:

Within a line, words are separated by one or more spaces. Line breaks have no other meaning: where you break the code is up to you.

What the loader ignores

LineWhat the loader does
Starts with ' (after any spaces)Ignores it: it's a comment
Starts with /Ignores it: it's a comment
Has a ' in the middleReads up to the quote mark and discards the rest
Starts with '# or /#It's a header line (below)
Starts with defDefines a variable; adds no tokens (Variables with def)
Anything elseIt's split into words and each one is a token

Watch out for two details. The slash only comments at the start of the line: a // in the middle is words that are 0. And any line that starts with the letters def is taken as a def, even if the word is a different one: defensa 50 defines a variable called nsa.

Encoding

The app reads the file as UTF-8 text. In comments you can write whatever you want, accents and all. In the code, though, only the ordinary characters of an English keyboard count: a word with an odd character (an accent, a non-breaking space copied from a web page, an invisible character) isn't recognized and is 0. For example, a stop with a non-breaking space in the middle no longer closes the gene. The The DNA editor warns you when it finds a word like that.

The '# header

Lines that start with '# (or /#) carry data about the bot, in the form '#name: value. The loader understands four:

LineWhat it stores
'#generation: 7The bot's generation
'#mutations: 3How many mutations its lineage has accumulated
'#tag: textA free-form tag, up to 45 characters
'#hash: …A 20-character signature of the preceding text

Any other '# line, or one with a value that isn't understood, is ignored without rejecting the bot. In the tag, letters outside basic English become question marks: '#tag: Acción ends up as Acci??n.

The '#hash is a check against hand editing. The engine computes it over all the text that comes before it, and recomputes it on loading. If it doesn't match, the generation and the mutations go back to 0; the DNA loads anyway. So, if you touch anything in an exported file (the code, the generation, or even if you add a comment at the top), the bot loses its history and goes back to generation 0. Changing line endings from CR+LF to LF doesn't break it. A file with no '#hash keeps whatever its header says.

How the engine exports a bot

In the app, the text of a living bot is in the DNA tab of the The inspector, with the Copy button. That text isn't the original file: the engine rebuilds it from the tokens, just like the original DarwinBots when saving a bot. If the bot has mutated since you opened it, Reload brings in the current version.

With this starting bot:

'#generation: 7
'#mutations: 3
' Turns 10 per cycle for 5 cycles
def pasos 50

cond
  *.pasos 5 <
start
  .aim * 10 add .setaim store
  .pasos inc   ' adds 1 to address 50
stop

what the engine exports is this (the lines of quote marks are gene comments that it adds):

'#generation: 7
'#mutations: 3

 cond
 *50 5 <
 start
 18 * 10 add .setaim store
 50 inc
 stop
''''''''''''''''''''''''  Gene:  1 Ends at position  14  '''''''''''''''''''''''

'#hash: …

Compare them and you'll see everything that changes:

Loading that text again gives the same bot, with the same generation. The only exception comes from Mutations: they can leave tokens that have no written form, and the engine exports them as VOID, a word that is 0 when reloaded. DNA like that doesn't come back identical.

Your bots, the Bestiary and files