NMLTutorial/Railtypetable
If you want to work with railtype labels, you need to teach NML about the labels you want to use. This is done by means of a railtypetable block. The railtypetable block can only be used in OpenTTD[1].
Railtypetable block
The railtypetable block contains a list of railtype labels, very similar to the cargotable block. Railtypetable blocks can do some more advanced things[2] than cargotable blocks, but that is outside the scope of this tutorial. There can be one railtypetable block in an NML file.
The railtypetable itself is no more than a list of railtype labels. The default railtype labels are "RAIL", "ELRL", "MONO", "MLEV", "3RDR". Custom defined railtype labels used by several track sets can be looked up in the list of railtype labels. This is what the general syntax looks like (for the purpose of this tutorial):
railtypetable { <railtype_label1> [, <railtype_label2> [, <railtype_label3> ... ]] }
You can add as many railtype labels to the railtypetable as you want/need. Railtype labels that start with a number (such as 3RDR
) must be written as quoted string. If a railtype label doesn't start with a number, you may omit the quotes.
The railtypetable must exist before you use any of the labels in your NML code, so the best place for it is somewhere near the top of your NML file.
Example
An example railtypetable block for the four railtypes available by default in OpenTTD:
railtypetable { RAIL, ELRL, MONO, MGLV }
Example use when you use labels starting with a number:
railtypetable { RAIL, ELRL, "3RDR", "3RDC" }
Referencing a railtype label
If you need to reference a railtype label from some other place in the code (e.g. from a property block), use the function railtype(<label>)
substituting <label>
with the actual railtype label from the table. If you've written the label in the table without quotes, don't use quotes here either. If you have a label as quoted string in the table, you need to use the quoted string format in this function as well.
NML Tutorial: Railtypetable
- ↑ In theory you should be able to use railtypetable blocks in NewGRFs for TTDPatch if you limit the table to
RAIL, MONO, MGLV
(in that order) and guard it by anif (ttd_platform == PLATFORM_OPENTTD)
. This however has not been tested by the author of this tutorial. Without a railtypetable block you can still use the labels RAIL, MONO and MGLV, but there will be no guarantee that this works properly on OpenTTD with different custom railtype NewGRFs loaded. - ↑ The advanced railtypetable is one that defines custom identifiers attached to a fallback label order. See the NML Documentation for details.