NML:If: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
content of nml r1625 |
Planetmaker (talk | contribs) Add hint for ternary operator |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
{{NMLNavBlocksyntax}} |
|||
if (expression) { |
if (expression) { |
||
block; |
block; |
||
| Line 13: | Line 15: | ||
param[2] = 5 |
param[2] = 5 |
||
} |
} |
||
</pre> |
|||
For a single variable or property assignment the ternary operator might be shorter: |
|||
result = boolean_value ? if_true : if_false; |
|||
e.g. |
|||
<pre style=example> |
|||
ground_sprite = (nearby_tile_type(0,0) == TILETYPE_DESERT) ? GROUNDSPRITE_DESERT : GROUNDSPRITE_NORMAL; |
|||
</pre> |
</pre> |
||
Latest revision as of 23:58, 3 September 2011
Vehicles, Stations, Roadstops, Canals, Towns, Houses, Industries (Tiles), Cargos, Airports+Tiles, Objects, Railtypes, Roadtypes, Tramtypes, Bridges, Badges, Terrain
if (expression) {
block;
} else {
block;
}
For example:
if (param[1] == 1) {
param[2] = 3
} else {
param[2] = 5
}
For a single variable or property assignment the ternary operator might be shorter:
result = boolean_value ? if_true : if_false;
e.g.
ground_sprite = (nearby_tile_type(0,0) == TILETYPE_DESERT) ? GROUNDSPRITE_DESERT : GROUNDSPRITE_NORMAL;