NML tutorial

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

Moderator: Graphics Moderators

User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: NML tutorial

Post by FooBar »

"grf parameters" is something known to almost every user of OpenTTDPatch. So to me it seems that we should keep that part named the way it is. And technically, whether set by the user or by the grf itself, both types of parameter are essentially the same thing.

Argument could work as a replacement for template parameter. I looked it up and is a correct term for variables fed to a function (in mathematics at least). As NML templates are mostly things that do math on some numbers, I think argument is a good alternative that both makes sense and isn't confusing.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML tutorial

Post by Yexo »

Eddi wrote:i'm rather thinking the "grf parameter" part is a bit of a misnomer, because they serve more as "global variables", which can be set by the GUI (-> action 14) or by the GRF (-> action D)
The problem with that is that "variable" is mostly used in varaction2 context. Hence "global variable" is "varaction2 variable that is available for all features".
User avatar
Hyronymus
Tycoon
Tycoon
Posts: 13235
Joined: 03 Dec 2002 10:36
Location: The Netherlands
Contact:

Re: NML tutorial

Post by Hyronymus »

Yexo wrote:
Eddi wrote:i'm rather thinking the "grf parameter" part is a bit of a misnomer, because they serve more as "global variables", which can be set by the GUI (-> action 14) or by the GRF (-> action D)
The problem with that is that "variable" is mostly used in varaction2 context. Hence "global variable" is "varaction2 variable that is available for all features".
GRF switch?
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML tutorial

Post by planetmaker »

That would be highly confusing with the keyword 'switch' as used for a decision statement.
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: NML tutorial

Post by FooBar »

Five new pages added to the tutorial today. It now teaches you about callbacks and switch blocks and illustrates that by means of an example articulated tram vehicle.

Next on the list is a rather advanced train example. It's a bit of a challenge for me as well as how to chop that up into managable pieces that still make sense. It "only" has 14 switch blocks, so I guess that alone needs to be two pages at least.

So there we go, the tutorial is more than halfway done and should already be really very usable to get most of you started on NML. If you understand the tutorial so far, you can probably can figure out the rest yourself.
User avatar
buckethead
Tycoon
Tycoon
Posts: 2014
Joined: 12 Jun 2009 07:21

Re: NML tutorial

Post by buckethead »

Gave a look at a few pages today, and it looks really well made and so clear that even a dummy like me can understand it. Thank you Sir! :D
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: NML tutorial

Post by FooBar »

You're welcome :)

I also just completed the train example. It uses a lot of advanced features of NML which you may not understand if you haven't looked at the road vehicle and tram examples first, but then you can make a very advanced train.

Along the lines you'll also learn something about railtypetable blocks and GRF parameters. With this the NML tutorial is nearly done. Last thing I intend to add is an example on making an object NewGRF, as that uses a completely different way of defining sprites compared to vehicles.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML tutorial

Post by planetmaker »

FooBar wrote:I also just completed the train example.(...)
I just read through the tutorial pages last night. They're probably the best introduction to NewGRF programming by a big margin which I've seen so far. Kudos! And a big thank you - it's really appreciated :-)
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: NML tutorial

Post by FooBar »

Thank you for your complimentings! :P

Hopefully the tutorial inspire people who previously thought making a NewGRF was impossible to give it a go. I tried to make it as entry-level as I possibly could; future must tell if I succeeded at that :)
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: NML tutorial

Post by FooBar »

Now the object example is done as well. For this example you'll also learn something about spritelayout blocks and version checks.

The tutorial is now very nearly done. All pages on which you learn something have been written. The finishing of the tutorial is in the minor details.
macee
Engineer
Engineer
Posts: 19
Joined: 20 May 2011 20:14

Re: NML tutorial

Post by macee »

Thank you for this very useful tutorial. This finally gave me the push to learn NML, and try to add something back to the community.

I have two comments/questions:
1. This is only a kind-of typo, but it took me a few minutes to discover the problem. In the train part of the tutorial, on this page: http://www.tt-wiki.net/wiki/NMLTutorial ... gle_engine, at the item block, you gave the identifier "item_icm" to the train, but here: http://www.tt-wiki.net/wiki/NMLTutorial ... rticulated at the Articulated part callback and the Wagon attach callback part you refer to it as "icm". After I changed the "item_icm" to "icm" the compilation was successful...
2. ...however, the grf doesn't work as it should be. The arrangements of front, rear and middle cars are all wrong. For example, the 3*4 car consist shows as a 4*3 car consist. See attached screenshot.

I copy pasted the code from this page: http://www.tt-wiki.net/wiki/NMLTutorial ... part_refit

Edit: forgot to attach screenshot:)
Attachments
nml tutorial bug.png
nml tutorial bug.png (12.25 KiB) Viewed 2472 times
Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: NML tutorial

Post by Hirundo »

These errors were just to test if anyone would try to compile the example code. Test successful, I'd say :wink:

Jokes aside, I made some small fixes to the code and all should be fine now, although I didn't test anything.
1) was indeed a kind-of-typo, I made the fix the other way around and changed all callbacks to use "item_icm".
2) In this case, the needed changes to "sw_icm_graphics" weren't copied to the full example code at the bottom of the page.
Create your own NewGRF? Check out this tutorial!
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: NML tutorial

Post by FooBar »

For those interested, I've just expanded the NML tutorial with a section on adding 32 bit sprites.

This is mainly aimed at 32bpp sprites for vehicles and other user-defined objects, as the tutorial does not (yet) have a section on replacements for base sprites. I may add that later.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 10 guests