Difference between revisions of "NMLTutorial/Railtypetable"

From TTWiki
Jump to navigationJump to search
(3RDR isn't default, some code tags and a link to the builtin functions)
(can always not use a railtypetable if only rail, mono and mglv are needed and change when to use railtype function)
Line 1: Line 1:
 
{{NMLTutorial}}
 
{{NMLTutorial}}
   
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<ref>In theory you should be able to use railtypetable blocks in NewGRFs for TTDPatch if you limit the table to <code>RAIL, MONO, MGLV</code> (in that order) and guard it by an <code>if (ttd_platform == PLATFORM_OPENTTD)</code>. This however has not been tested by the author of this tutorial. Without a railtypetable block you can still use the labels <code>RAIL</code>, <code>MONO</code> and <code>MLEV</code>, but there will be no guarantee that this works properly on OpenTTD with different custom railtype NewGRFs loaded.</ref>.
+
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<ref>In theory you should be able to use railtypetable blocks in NewGRFs for TTDPatch if you limit the table to <code>RAIL, MONO, MGLV</code> (in that order) and guard it by an <code>if (ttd_platform == PLATFORM_OPENTTD)</code>. This however has not been tested by the author of this tutorial. Without a railtypetable block you can still use the labels <code>RAIL</code>, <code>MONO</code> and <code>MGLV</code>.</ref>.
   
   
Line 7: Line 7:
 
The railtypetable block contains a list of railtype labels, very similar to the cargotable block. Railtypetable blocks can do some more advanced things<ref>The advanced railtypetable is one that defines custom identifiers attached to a fallback label order. See the [http://newgrf-specs.tt-wiki.net/wiki/NML:Railtypetable NML Documentation] for details.</ref> than cargotable blocks, but that is outside the scope of this tutorial. There can be one railtypetable block in an NML file.
 
The railtypetable block contains a list of railtype labels, very similar to the cargotable block. Railtypetable blocks can do some more advanced things<ref>The advanced railtypetable is one that defines custom identifiers attached to a fallback label order. See the [http://newgrf-specs.tt-wiki.net/wiki/NML:Railtypetable NML Documentation] for details.</ref> 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 <code>RAIL</code>, <code>ELRL</code>, <code>MONO</code> and <code>MLEV</code>. Custom defined railtype labels used by several track sets can be looked up in the [http://newgrf-specs.tt-wiki.net/wiki/RailtypeLabels list of railtype labels]. This is what the general syntax looks like (for the purpose of this tutorial):
+
The railtypetable itself is no more than a list of railtype labels. The labels of the default railtypes are <code>RAIL</code>, <code>ELRL</code>, <code>MONO</code> and <code>MGLV</code>. Custom defined railtype labels used by several track sets can be looked up in the [http://newgrf-specs.tt-wiki.net/wiki/RailtypeLabels list of railtype labels]. This is what the general syntax looks like (for the purpose of this tutorial):
   
 
<pre style="white-space: pre-wrap">
 
<pre style="white-space: pre-wrap">
Line 38: Line 38:
   
 
== Referencing a railtype label ==
 
== 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 [http://newgrf-specs.tt-wiki.net/wiki/NML:Builtin_functions function] <code>railtype(<label>)</code> substituting <code><label></code> 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.
+
If you need to reference a railtype label from some other place in the code (e.g. from a property block), use the [http://newgrf-specs.tt-wiki.net/wiki/NML:Builtin_functions function] <code>railtype(<label>)</code> substituting <code><label></code> for railtype labels that start with a number. Also use the quoted format inside the function. Railtype labels that don't start with an number can be referenced elsewhere also without the function in the unquoted format.
   
 
{{NMLTutorialNavbar|Train|Train single engine}}
 
{{NMLTutorialNavbar|Train|Train single engine}}

Revision as of 21:29, 27 August 2011

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 labels of the default railtypes are RAIL, ELRL, MONO and MGLV. 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> for railtype labels that start with a number. Also use the quoted format inside the function. Railtype labels that don't start with an number can be referenced elsewhere also without the function in the unquoted format.


NML Tutorial: Railtypetable


  1. 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 an if (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.
  2. The advanced railtypetable is one that defines custom identifiers attached to a fallback label order. See the NML Documentation for details.