[NML] Using is_city town variable in if_else

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

Post Reply
User avatar
GuilhermeJK
Engineer
Engineer
Posts: 55
Joined: 01 Nov 2014 05:24
Location: São José dos Campos, Brazil

[NML] Using is_city town variable in if_else

Post 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
Cadde
Transport Coordinator
Transport Coordinator
Posts: 290
Joined: 07 Oct 2004 12:51

Re: [NML] Using is_city town variable in if_else

Post 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?
User avatar
GuilhermeJK
Engineer
Engineer
Posts: 55
Joined: 01 Nov 2014 05:24
Location: São José dos Campos, Brazil

Re: [NML] Using is_city town variable in if_else

Post 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)
		}
}
Cadde
Transport Coordinator
Transport Coordinator
Posts: 290
Joined: 07 Oct 2004 12:51

Re: [NML] Using is_city town variable in if_else

Post 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.
User avatar
GuilhermeJK
Engineer
Engineer
Posts: 55
Joined: 01 Nov 2014 05:24
Location: São José dos Campos, Brazil

Re: [NML] Using is_city town variable in if_else

Post 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
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 3 guests