Difference between revisions of "NMLTutorial/Railtypetable"
(page contents) |
m (pre class) |
||
(4 intermediate revisions by the same user not shown) | |||
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.</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 |
+ | 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 |
+ | <pre class="pseudo"> |
railtypetable { |
railtypetable { |
||
<railtype_label1> [, <railtype_label2> [, <railtype_label3> ... ]] |
<railtype_label1> [, <railtype_label2> [, <railtype_label3> ... ]] |
||
Line 22: | Line 22: | ||
An example railtypetable block for the four railtypes available by default in OpenTTD: |
An example railtypetable block for the four railtypes available by default in OpenTTD: |
||
+ | <pre class="example"> |
||
− | <pre style="color:darkblue; white-space: pre-wrap"> |
||
railtypetable { |
railtypetable { |
||
RAIL, ELRL, MONO, MGLV |
RAIL, ELRL, MONO, MGLV |
||
Line 30: | Line 30: | ||
Example use when you use labels starting with a number: |
Example use when you use labels starting with a number: |
||
+ | <pre class="example"> |
||
− | <pre style="color:darkblue; white-space: pre-wrap"> |
||
railtypetable { |
railtypetable { |
||
RAIL, ELRL, "3RDR", "3RDC" |
RAIL, ELRL, "3RDR", "3RDC" |
||
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 function <code>railtype(<label>)</code> substituting <code><label></code> |
+ | 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 |
+ | {{NMLTutorialNavbar|Train|Train single engine}} |
Latest revision as of 22:15, 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
- ↑ 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 labelsRAIL
,MONO
andMGLV
. - ↑ The advanced railtypetable is one that defines custom identifiers attached to a fallback label order. See the NML Documentation for details.