NML:Parameter assignment: Difference between revisions
content of nml r1625 |
Named parameters and constants. |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{{NMLNavBlocksyntax}} |
|||
==Parameters== |
|||
param[<expression>] = <expression>; |
param[<expression>] = <expression>; |
||
Set a parameter to the given expression. Neither of the two expressions has to be constant, the following is perfectly valid: |
Set a parameter to the given [[NML:Block syntax#Syntax|expression]]. Neither of the two expressions has to be constant, the following is perfectly valid: |
||
<pre style="color:blue"> |
<pre style="color:blue"> |
||
param[param[2] + 1] = param[3] * param[4]; |
param[param[2] + 1] = param[3] * param[4]; |
||
</pre> |
</pre> |
||
Parameters can also be named, then it is possible to access them by that name instead of index. |
|||
<pre style="color:blue"> |
|||
custom_bit_mask = add_trains + (add_planes << 1); |
|||
</pre> |
|||
'''Note:''' When assigning value to named parameter that has not been used/defined earlier it is given an unused index, therefore it is better not to mix named parameters with unnamed ones in one grf. |
|||
==Compile time values== |
|||
Since {{nml|0.7.6}} it is possible to create user defined constants. They work the same way as default ones. |
|||
<pre> |
|||
const <expression> = <expression>; |
|||
</pre> |
|||
<pre style="color:blue"> |
|||
const CC_WEIRD = 12; |
|||
</pre> |
|||
It is adviced to use screaming snake case for constants to distinguish them from runtime expressions. |
|||
Latest revision as of 09:14, 8 June 2026
Vehicles, Stations, Roadstops, Canals, Towns, Houses, Industries (Tiles), Cargos, Airports+Tiles, Objects, Railtypes, Roadtypes, Tramtypes, Bridges, Badges, Terrain
Parameters
param[<expression>] = <expression>;
Set a parameter to the given expression. Neither of the two expressions has to be constant, the following is perfectly valid:
param[param[2] + 1] = param[3] * param[4];
Parameters can also be named, then it is possible to access them by that name instead of index.
custom_bit_mask = add_trains + (add_planes << 1);
Note: When assigning value to named parameter that has not been used/defined earlier it is given an unused index, therefore it is better not to mix named parameters with unnamed ones in one grf.
Compile time values
Since NML 0.7.6 it is possible to create user defined constants. They work the same way as default ones.
const <expression> = <expression>;
const CC_WEIRD = 12;
It is adviced to use screaming snake case for constants to distinguish them from runtime expressions.