NML tutorial
Moderator: Graphics Moderators
Re: NML tutorial
"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.
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.
Re: NML tutorial
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".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)
Re: NML tutorial
GRF switch?Yexo wrote: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".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)
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: NML tutorial
That would be highly confusing with the keyword 'switch' as used for a decision statement.
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: NML tutorial
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.
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.
- buckethead
- Tycoon
- Posts: 2014
- Joined: 12 Jun 2009 07:21
Re: NML tutorial
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! 

Re: NML tutorial
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.

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.
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: NML tutorial
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 appreciatedFooBar wrote:I also just completed the train example.(...)

OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: NML tutorial
Thank you for your complimentings!
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

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

Re: NML tutorial
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.
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.
Re: NML tutorial
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:)
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 (12.25 KiB) Viewed 2468 times
Re: NML tutorial
These errors were just to test if anyone would try to compile the example code. Test successful, I'd say
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.

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!
Re: NML tutorial
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.
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.
Who is online
Users browsing this forum: No registered users and 8 guests