Page 1 of 1

[NML] Using is_city town variable in if_else

Posted: 02 Jul 2017 23:49
by GuilhermeJK
Can "is_city" town variable be accessed to be used in a if_else statement in NML?

I tried if ((is_city) == 1){ but the terminal game me a message:

Code: Select all

←[Knmlc ERROR: "CRABS.nml", line 38: Unrecognized identifier 'is_city' encountered

Re: [NML] Using is_city town variable in if_else

Posted: 03 Jul 2017 00:20
by Cadde
Show us a sample of the code block you are working on?

The "is_city" variable is only ever defined in certain scopes:

https://newgrf-specs.tt-wiki.net/wiki/NML:Towns
Towns aren't a NewGRF feature of their own but town variables can be accessed via the parent scope of stations, houses and industries.
Hence, you must be in one of those scopes to be able to use it.

Also, maybe a ternary operator might be what you are looking for?

Code: Select all

property = is_city ? 1 : 0;
So where are you using it and what's the goal?

Re: [NML] Using is_city town variable in if_else

Posted: 03 Jul 2017 00:41
by GuilhermeJK
I was testing an idea of giving town one set of road sprites and cities another. Like this:

Code: Select all

if ((is_city) == 1){
	replace dirt_road (1332, "gfx/test.png"){
		template_roads(1, 1)
		}
}else{
	replace sett_road (1332, "gfx/test.png"){
		template_roads(1, 42)
		}
}

Re: [NML] Using is_city town variable in if_else

Posted: 03 Jul 2017 08:47
by Cadde
And is that inside a FEAT_HOUSES, FEAT_STATIONS or FEAT_INDUSTRIES block?
I suspect what you are trying to achieve there isn't possible. But i don't know. Either way, the "is_city" variable is only available inside it's related feature as explained in the link i gave you.

Re: [NML] Using is_city town variable in if_else

Posted: 03 Jul 2017 18:38
by GuilhermeJK
Thanks for your answer, definitively it is not possible to use is_city the way I thought. Will have to change plans :) Thanks