Feature Request #2979

usage of variables in ranges for switches

Added by planetmaker over 8 years ago. Updated over 8 years ago.

Status:NewStart date:2011-08-17
Priority:NormalDue date:
Assignee:-% Done:


Target version:-


code sometimes looks nicer, if variables are used in switch ranges:

switch(FEAT_INDUSTRYTILES, SELF, THIS_ID(name), nearby_tile_height(0,0)) { \
0 .. snowline_height: inrange; \
outrange; \

for the currently working option

switch(FEAT_INDUSTRYTILES, SELF, THIS_ID(name), (nearby_tile_height(0,0) <= maxh) && (nearby_tile_height(0,0) >= minh)) { \
1: inrange; \
outrange; \


#1 Updated by planetmaker over 8 years ago

A bit more explanation:

10:56 Yexo: no, it's an action2 var
10:57 planetmaker: ho
10:57 Yexo: which means it can't be used in the range at all
10:57 planetmaker: why not?
10:57 planetmaker: the two code snippets I posted are equivalent
10:57 planetmaker: it could be re-written internally by NML
10:57 Yexo: because the range is something "hardcoded" in the output, you can only change it by action6 (so actionD variables are ok)
10:57 Yexo: of course rewriting might be possible
10:58 planetmaker: that's what I actually thought of :-)
10:58 planetmaker: splitting such range check into several switches with 0 and 1 ranges
10:58 planetmaker: makes for nicer NML code in the grf
10:58 Yexo: but what if you have "0..a: 1; a..b: 2; b..c: 3;"? That will result in a very ugly rewrite
10:59 planetmaker: just a small chain of switches
10:59 planetmaker: I'd not consider it ugly
10:59 Yexo: ah, a chain of switches, ok

Also available in: Atom PDF