NML - a Newgrf Meta Language

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

Moderator: Graphics Moderators

jotty
Engineer
Engineer
Posts: 9
Joined: 23 May 2011 21:31

Re: NML - a Newgrf Meta Language

Post by jotty »

michael blunck wrote: Yeah, you didn´t post a grf file but the source code to compile a one, correct. Be assured that people will take the file in the form it has been posted here by you and compile it into a newgrf without changing its grf-ID.
You're right with that. If this would happen to me, I'd look here for answers and could find them in your reply.
michael blunck wrote: I.e., you´ll have to change the grf-ID in your post to something unique. Where´s the problem?
There's no problem, I just did it (hoping nobody else is still using jh). If so, people are warned about a possible wrong grf id.

Is there a complete list of all used grfids anywhere where one can register his/her new grf id?
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

jotty wrote:Is there a complete list of all used grfids anywhere where one can register his/her new grf id?
There unfortunately is not.

There is an (inconvient) list of NewGRFs which are uploaded to Bananas. There it is made sure though, that no other NewGRF can be uploaded which has the same ID. You can view the (unsorted) list of all IDs uploaded there: http://bananas.openttd.org/en/newgrf/
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: NML - a Newgrf Meta Language

Post by michael blunck »

jotty wrote: [...] Is there a complete list of all used grfids anywhere where one can register his/her new grf id?
Not that I know of. However, GRFcrawler allows searching by grf-IDs.

regards
Michael
Image
jotty
Engineer
Engineer
Posts: 9
Joined: 23 May 2011 21:31

Re: NML - a Newgrf Meta Language

Post by jotty »

michael blunck wrote:
Not that I know of. However, GRFcrawler allows searching by grf-IDs.

regards
Michael
Ok, so how can I seek with that tool for jh\04\01 ? Escape-Codes don't work...
michael blunck
Tycoon
Tycoon
Posts: 5954
Joined: 27 Apr 2005 07:09
Contact:

Re: NML - a Newgrf Meta Language

Post by michael blunck »

jotty wrote: Ok, so how can I seek with that tool for jh\04\01 ? Escape-Codes don't work...
http://grfcrawler.tt-forums.net/index.p ... q=6a680401

HTH
regards
Michael
Image
User avatar
Ammler
President
President
Posts: 953
Joined: 18 Jun 2006 18:18
Location: Switzerland
Contact:

Re: NML - a Newgrf Meta Language

Post by Ammler »

there is also this list:
http://bundles.openttdcoop.org/grfpack/ ... grfid.list

(bananas and other nice newgrfs combined)

Also why don't you post the grf (with valid id)

I don't think MB does forbid addons, there is for example also a newships mod.

Greets
Ammler
jotty
Engineer
Engineer
Posts: 9
Joined: 23 May 2011 21:31

Re: NML - a Newgrf Meta Language

Post by jotty »

Ammler wrote:there is also this list:
http://bundles.openttdcoop.org/grfpack/ ... grfid.list

(bananas and other nice newgrfs combined)
Ok, thanks.
Ammler wrote:Also why don't you post the grf (with valid id)

I don't think MB does forbid addons, there is for example also a newships mod.
Yes, but I think this little example is not worth a new grf file. There should me more additions (as cargo wagon changes) that I currently can't do. And with the source code anyone can create its own grf file with special other extensions as pleased.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

jotty wrote:And with the source code anyone can create its own grf file with special other extensions as pleased.
You over-estimate the average grf user. Asking to install grf development tools in order to get a newgrf which fixes one problem is not little asking for.
jotty
Engineer
Engineer
Posts: 9
Joined: 23 May 2011 21:31

Re: NML - a Newgrf Meta Language

Post by jotty »

planetmaker wrote:
jotty wrote:And with the source code anyone can create its own grf file with special other extensions as pleased.
You over-estimate the average grf user. Asking to install grf development tools in order to get a newgrf which fixes one problem is not little asking for.
You're right that it takes some time to generate the newgrf itself. You're right to look for a newgrf instead of source code. But you're not right in fixing problems with this little code. There is no problem with dbsexl; dbsetxl is perfect. I just wanted to play from 1850 on, nothing more. And I found a way how to do this by the help of you people. This is what I wanted to document, nothing more.
User avatar
Ammler
President
President
Posts: 953
Joined: 18 Jun 2006 18:18
Location: Switzerland
Contact:

Re: NML - a Newgrf Meta Language

Post by Ammler »

problem doesn't need to be something bad, there are multiple problems with dbsetxl... ;-)
User avatar
lawton27
Tycoon
Tycoon
Posts: 1418
Joined: 03 Aug 2009 14:29
Location: Manchester

Re: NML - a Newgrf Meta Language

Post by lawton27 »

Hi am I doing something stupid wrong or can I not use parameters to enable/disable certain town names from a town name grf like this?

Code: Select all

town_names
{
    styles : string(TTD_MENU_NAME);
    {
        text("Example", param[0]),
        text("Test", param[1]),
        
    }
}
I get the error on compiling

Code: Select all

 Expected a compile-time integer constant 
Thanks for any help,

Lawton27
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

This is unfortunately not supported by NML, nor will it be. You can do something like this:

Code: Select all

town_names
{
    styles : string(TTD_MENU_ALL_NAMES);
    {
        text("Example", 1),
        text("Test", 1),
    }
}
town_names
{
    styles : string(TTD_MENU_EXAMPLE_NAMES);
    {
        text("Example", 1),
    }
}
town_names
{
    styles : string(TTD_MENU_TEST_NAMES);
    {
        text("Test", 1),
    }
}
User avatar
lawton27
Tycoon
Tycoon
Posts: 1418
Joined: 03 Aug 2009 14:29
Location: Manchester

Re: NML - a Newgrf Meta Language

Post by lawton27 »

Ah ok, thanks.
User avatar
Hyronymus
Tycoon
Tycoon
Posts: 13235
Joined: 03 Dec 2002 10:36
Location: The Netherlands
Contact:

Re: NML - a Newgrf Meta Language

Post by Hyronymus »

Last weekend I started putting up a stub on the new TT-wiki about NML. The idea is to expand it into a comprehensive and understandable "manual" on coding in NML.

From my own perception I believe NML can bring coding much closer to players than NFO due to the 'logical' and normal readable construction of lines of code. But as mentioned on the current development site of NML much documentation on how to use the syntax is missing. Illustrations are powerful tools to explain certain features and I hope that those with NML experience will contribute code with ample explanation to the NML wiki. An easy-readable way of achieving that has yet to be conceived, please speak up if you have an idea how to achieve this.

What I've written sofar can be found here: http://www.tt-wiki.net/wiki/NMLTutorial

Please remember: all contributions to the Wiki must be in line with the GNU General Public Licence 2.0 license: http://www.gnu.org/licenses/gpl-2.0.html.
Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: NML - a Newgrf Meta Language

Post by Hirundo »

Since I do not expect everyone to read every NML commit message, here a quick overview of some recent NML features:

The most important one is that you can now define callbacks directly in the graphics block. You can also specify return values there, so simple callbacks no longer need any switch-blocks. A list of callbacks is included in the documentation of each feature (docs/feature.html). Example:

Code: Select all

item(FEAT_ROADVEHS, some_articulated_tram) {
    graphics {
        cargo_capacity: return 20; // 20 per part, total = 80
        /* tram is made up of 4 parts in total, so add 3 articulated parts */
        articulated_part: return (extra_callback_info1 <= 3) ? some_articulated_tram : 0xFF;
        sound_effect: sound_effect_switch; // sound effect callback handled by a switch (not included here)
        MAIL: tram_graphics_mail; // special graphics when refitted to mail (not included here)
        default: tram_graphics_pax; // default graphics for the passenger cargo (not included here)
    }
}
This way of defining callbacks is the recommended way to go. The old style (reading the current_callback variable) is still supported for backwards compatibility only.
The main advantage is that allows NML to create a better abstraction of the various quirks and inconsistencies that are present in NFO, in order to provide a better coding experience.
For example, the new method automatically sets the callback_flags property for you, so you can't forget a bit there and wonder why your grf doesn't work.

Return values in graphics or [random]switch blocks can now also access variables, as well as the parameters of a produce(..) statement.

Advanced spritelayouts, a recent NFO feature, have also been included in NML. You can now access (temporary or persistent) registers and variables from inside a spritelayout. This way, you no longer have to define a separate layout for each slightly different tile.

Last but not least, it is no longer necessary to define spritegroups in many cases. A spritegroup is equivalent to a 'real' action2 that combines several spritesets. In all cases except vehicles with multiple loading stages, these were just boilerplate code. Therefore, it has now been made possible to refer directly from a switch/graphics block to a spriteset. This has made spritegroups completely obsolete for cargos, canals, railtypes and airports, so spritegroups for those features have been declared deprecated and support will be removed in the future.

Happy coding :P If you have questions, suggestions or wish to help with development, feel free to post here or ask on IRC (#openttdcoop.devzone channel).
Create your own NewGRF? Check out this tutorial!
User avatar
Dwight_K._Schrute
Traffic Manager
Traffic Manager
Posts: 209
Joined: 01 Sep 2010 11:29

Re: NML - a Newgrf Meta Language

Post by Dwight_K._Schrute »

Hey guys,

I'm starting to learn NML and it works just fine for trains so far. So thank you for the good documentation. But now I'm having a problem and can't find anything about it in the documentation. I want to Code a railcar with different liveries. So when you refit this train in the depot you get the options:

passengers (livery 1)
passengers (livery 2)
...
passengers (livery n)
tourists (livery 1)
...
tourists (livery n)

But I don't have any idea how to achieve this. This is what I have so far for the normal railcar with one livery:

Code: Select all

spriteset(railcar, "RS.png") {
	[82,8,  8,22,   -3,0]
	[98,8, 22,17,  -21, -3]
	[130,8, 31,12,  -23, -6]
	[178,8, 22,17,   -15, -11]
	[82,8,  8,22,   -2,-5]
	[98,8, 22,17,  -5, -11]
	[130,8, 31,12,  0, -6]
	[178,8, 22,17,   4, -2]
}
item (FEAT_TRAINS, railcar,1) {
	property {
		sprite_id:			SPRITE_ID_NEW_TRAIN;
		name:               string(STR_NAME_RAILCAR);
		climates_available: ALL_CLIMATES;
		introduction_date:  date(1940,1,1);
		speed:              20 km/h;
		vehicle_life:		20;
		loading_speed:		10;
		cost_factor:		1;
		running_cost_factor:1;
		track_type:			RAIL;
		power:				690 hp;
		engine_class:		ENGINE_CLASS_DIESEL;
		cargo_capacity:		100;
		weight:				40 tons;
		tractive_effort_coefficient: 0.06;
		refittable_cargo_classes: bitmask(CC_PASSENGERS);
				}
	graphics{
	railcar;
	     
I thought maybe I have to do something with "refittable_cargo_types" or classes. But I don't know what to wirte there but "bitmask(...)" It would bw nice if you could help me :)
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

For refits between different cargos it's sufficient to just allow those cargos. You then can select a different graphics set depending on the current_cargo variable.

If you want to make use of several refits for a single cargo, you'll have to resort to the cargo subtype callback and then select the graphics not only depending on the variable cargo_type_in_veh but additionally also on the variable cargo_subtype.

See http://dev.openttdcoop.org/projects/nml ... _train.nml for an example (it uses the 3 and 4 wagon refit). This example should ship with recent nightlies of NML.

EDIT: it could look similar to this:

Code: Select all

switch (FEAT_TRAINS, SELF, bulk_wagon_bauxite_livery_switch, cargo_subtype) {
    1: bulk_wagon_bauxite_livery1_group;
    2: bulk_wagon_bauxite_livery2_group;
    bulk_wagon_bauxite_livery_default_group;
}
// similiar for other cargos here 
(...)

// main cargo type switch
switch(FEAT_TRAINS, SELF, bulk_wagon_switch, cargo_type_in_veh) {
    AORE: bulk_wagon_bauxite_livery_switch;
    CERE: bulk_wagon_grain_livery_switch;
    CLAY: bulk_wagon_clay_livery_switch;
}
(...)

switch (FEAT_TRAINS, SELF, bulk_wagon_bauxite_livery_text_switch, cargo_subtype) {
    0: return string(STR_BULK_WAGON_BAUXITE_LIVERY_DEFAULT);
    1: return string(STR_BULK_WAGON_BAUXITE_LIVERY1);
    2: return string(STR_BULK_WAGON_BAUXITE_LIVERY2);
    return 0xFF;
}
// now similar for other cargos (not shown here)

(...)

switch (FEAT_TRAINS, SELF, bulk_wagon_cargo_livery_text_switch, cargo_type_in_veh) {
    AORE: bulk_wagon_bauxite_livery_text_switch;
    CERE: bulk_wagon_grain_livery_text_switch;
    CLAY: bulk_wagon_clay_livery_text_switch;
}

item (FEAT_TRAINS, SELF, bulk_wagon) {
    graphics {
        cargo_subtype_text: bulk_wagon_cargo_livery_text_switch;
    }
}
User avatar
Dwight_K._Schrute
Traffic Manager
Traffic Manager
Posts: 209
Joined: 01 Sep 2010 11:29

Re: NML - a Newgrf Meta Language

Post by Dwight_K._Schrute »

Thank you very much planetmaker,

I looked into it yesterday and it's not working (yet). I'll have to try again today... the examples are very good so I hope it will be no big problem :)

If I'm still having problems I will write them here in detail. Thanks again...
User avatar
Dwight_K._Schrute
Traffic Manager
Traffic Manager
Posts: 209
Joined: 01 Sep 2010 11:29

Re: NML - a Newgrf Meta Language

Post by Dwight_K._Schrute »

Ok it is me again. Now I have the possibility to refit in different liveries. That means it shows the options in the refit GUI. But what still is missing and what I can't figure out is how to tell the NewGRF which spriteset it should take depending on the chosen livery. Te second switch obviously does not have an influence...

Code: Select all

switch (FEAT_TRAINS, SELF, regio_shuttle_livery_text_switch, cargo_subtype) {
    0: return string(STR_REGIO_SHUTTLE_LIVERY_DEFAULT);
    1: return string(STR_REGIO_SHUTTLE_LIVERY1);
    2: return string(STR_REGIO_SHUTTLE_LIVERY2);
    return 0xFF;
}
switch (FEAT_TRAINS, SELF, regio_shuttle_livery_switch, cargo_subtype){
	1: regio_shuttle_livery1;
	2: regio_shuttle_livery2;
	regio_shuttle_livery_default;
}

(...)
				}
	graphics{
	default: regio_shuttle_livery_default;
	purchase: regio_shuttle_purchase;
	cargo_subtype_text: regio_shuttle_livery_text_switch;
	         }
}
oberhümer
Tycoon
Tycoon
Posts: 1283
Joined: 23 Oct 2009 19:35
Location: Here and there, sometime or another

Re: NML - a Newgrf Meta Language

Post by oberhümer »

I've got a problem too... This piece of NML code doesn't make a new vehicle available, and I see absolutely no reason why. The zipped full source code of the GRF this is coming from plus what is produced at the end is also attached. No error is generated, my version of NML is the Windows .exe r1513.

Code: Select all

spriteset(model_t_set, "src/gfx/model_t.png") {
	template_28px(1,1)
}
spritegroup model_t_grp {
	loaded: model_t_set;
	loading: model_t_set;
}
switch(FEAT_ROADVEHS, SELF, model_t_text_switch, build_year) {
	return string(STR_INFO_CITY_TRAFFIC);
}

switch(FEAT_ROADVEHS, SELF, model_t_cb_switch, current_callback) {
	VEH_CB_TEXT_PURCHASE_SCREEN: model_t_text_switch;
	model_t_grp;
}

item(FEAT_ROADVEHS, model_t) {
	property {
		name: string(STR_FORD_MODEL_T);
		introduction_date: date(1910,01,01);
		climates_available: ALL_CLIMATES;
		model_life: 20;
		vehicle_life: 25;
		reliability_decay: 17;
		refittable_cargo_types: 1;//bitmask(PASS);
		loading_speed: 4;
		cost_factor: 25;
		running_cost_factor: 4;		
		sprite_id: SPRITE_ID_NEW_ROADVEH;
		speed: 35km/h;
		misc_flags: 0;
		running_cost_base: RUNNING_COST_ELECTRIC;
		power: 20hp;
		weight: 1ton;
		tractive_effort_coefficient: 0.6;
		cargo_capacity: 8;
		sound_effect: SOUND_BUS_START_PULL_AWAY;
	}
	graphics {
		model_t_cb_switch;
	}
}
This is the content of "src/buses/model_t.pnml", which is included in "src/narvs.pnml".
Attachments
narvs-new.zip
(607.4 KiB) Downloaded 133 times
narvs.grf
(2.45 KiB) Downloaded 111 times
--- Licenses: GNU LGPL, version 2 or newer, code and graphics. CC-By-SA, graphics, alternatively. If you're using any, I'd like to hear about it --- Call them "track types" ---
--- Mostly inactive developer for: NuTracks - Central European Train Set --- Running/compiling for: Linux (x86) - Android - Windows (32/64 bit) ---

--- Need a file packer? 7-Zip --- BOINC - use your computing power to benefit science --- Block trackers, not ads --- Unix in dispersible pellets, the formula for the future. ---
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 2 guests