NML tutorial
Moderator: Graphics Moderators
NML tutorial
The NML tutorial ia available at the TT-Wiki: http://www.tt-wiki.net/wiki/NMLTutorial
This tutorial helps you install NML, explains different NML concepts and helps you understand those concepts by the means of examples that are interwoven in the more technical explanations of the syntax. It is meant to be read from top to bottom and every concept introduced is clarified by an example of actual NML code. The further you get in the tutorial, some concepts will be repeated by different examples and extended with new concepts.
I hope this tutorial helps anybody wanting to start with NML and not knowing where to start exactly. If you have any question on the tutorial content, please feel free to ask here. Please use a different topic if you just need help with your personal NML project.
This tutorial helps you install NML, explains different NML concepts and helps you understand those concepts by the means of examples that are interwoven in the more technical explanations of the syntax. It is meant to be read from top to bottom and every concept introduced is clarified by an example of actual NML code. The further you get in the tutorial, some concepts will be repeated by different examples and extended with new concepts.
I hope this tutorial helps anybody wanting to start with NML and not knowing where to start exactly. If you have any question on the tutorial content, please feel free to ask here. Please use a different topic if you just need help with your personal NML project.
Last edited by FooBar on 29 Aug 2011 11:05, edited 1 time in total.
Re: NML tutorial
Once again amazing work FooBar
You seem to have switched up the -c and -u flags (-c is for cropping), so I've fixed that.

You seem to have switched up the -c and -u flags (-c is for cropping), so I've fixed that.
Re: NML tutorial
ahh, yes. That indeed is a mixup, as I indeed meant -c. Especially as -u isn't a very good idea... Thanks for the fix.
As I couldn't sleep, I made some plans for what's next in the tutorial. I decided to add an example from the dutch trams as a means to illustrate some basic switches and callbacks. Then continue with the train example from the nml source as a more advanced example of swiches and callbacks, as already listed in the tutorial menu.
Now back to sleep
As I couldn't sleep, I made some plans for what's next in the tutorial. I decided to add an example from the dutch trams as a means to illustrate some basic switches and callbacks. Then continue with the train example from the nml source as a more advanced example of swiches and callbacks, as already listed in the tutorial menu.
Now back to sleep

Re: NML tutorial
Awesome work 

Spanish translation of OpenTTD
Extended heightmaps
Have fun, don't quarrel too much and add as many advanced settings as you can.
Extended heightmaps
Have fun, don't quarrel too much and add as many advanced settings as you can.
Re: NML tutorial
I expanded the tutorial a little bit. Now there's something on templates and the cargotable and the road vehicle example is complete.
Next will be an introduction to callbacks and switches, illustrated by an articulated tram example. But not today
Next will be an introduction to callbacks and switches, illustrated by an articulated tram example. But not today

Re: NML tutorial
Thank you a lot, FooBar
.

Re: NML tutorial
Overall I can only say (again!) that you did an excellent job! I do have some comments:
NML has no such limitation, you can even do calculations on the offsets if you want to (even though I don't see a good use-case for that).http://www.tt-wiki.net/wiki/NMLTutorial/Template wrote:Combine this with the fact that you can do any mathematical calculation on the values for left_x, upper_y, width and height (though not on the offsets), you can make a template as complex as you want.
Not true, NML limits you to exactly one cargotable, regardless of whether that cargotable is inside an if-block or not.http://www.tt-wiki.net/wiki/NMLTutorial/Cargotable wrote:very NewGRF can have exactly one cargotable (but you may select from several using if/else statements).
Re: NML tutorial
Hyronymus, Terkhen and Yexo, thanks for your kind words.
I added this as a footnote, just to be complete.
I appreciate your comments and if you (or anybody else) finds something that isn't correct or not clear please let me know. I like to think that I know how to code in NML, but am aware that I don't know every last detail. So keep those comments coming
Technically you're right. But because this states that you cannot use parameters for the offsets, I simplified it a bit not to bother users with too much details. I don't see a use for calculations in offsets either for as long as you can't use parameters in them.Yexo wrote:NML has no such limitation, you can even do calculations on the offsets if you want to (even though I don't see a good use-case for that).http://www.tt-wiki.net/wiki/NMLTutorial/Template wrote:Combine this with the fact that you can do any mathematical calculation on the values for left_x, upper_y, width and height (though not on the offsets), you can make a template as complex as you want.
I added this as a footnote, just to be complete.
I didn't know that. Duly noted and fixed.Yexo wrote:Not true, NML limits you to exactly one cargotable, regardless of whether that cargotable is inside an if-block or not.http://www.tt-wiki.net/wiki/NMLTutorial/Cargotable wrote:very NewGRF can have exactly one cargotable (but you may select from several using if/else statements).
I appreciate your comments and if you (or anybody else) finds something that isn't correct or not clear please let me know. I like to think that I know how to code in NML, but am aware that I don't know every last detail. So keep those comments coming

Re: NML tutorial
... i do have a use case for different offsets
and i haven't seen anything wrong with it.
Edit: i think the word "parameter" in the link above is confusing/misleading. there is a "template parameter" and a "grf parameter", and i think the two meanings collide here. what is probably meant is that grf-parameters may not be used for realsprites, but other calculations and template-parameters are fine.
and i haven't seen anything wrong with it.
Edit: i think the word "parameter" in the link above is confusing/misleading. there is a "template parameter" and a "grf parameter", and i think the two meanings collide here. what is probably meant is that grf-parameters may not be used for realsprites, but other calculations and template-parameters are fine.
Re: NML tutorial
You mean you use template parameters in the offsets? As I understood that was the thing that was not possible...
Maybe someone more familiar with the NML source code can clarify this once and for all.
I agree with you that "parameter" is confusing. I decided to rename them to "template parameter" to hopefully reduce/avoid this confusion. The remainder of the tutorial will spreak of "template parameter" and "grf parameter" where applicable, to make explicitly clear what is meant by "parameter".
Maybe someone more familiar with the NML source code can clarify this once and for all.
I agree with you that "parameter" is confusing. I decided to rename them to "template parameter" to hopefully reduce/avoid this confusion. The remainder of the tutorial will spreak of "template parameter" and "grf parameter" where applicable, to make explicitly clear what is meant by "parameter".
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: NML tutorial
I know of no limitation to use any template parameter within the template in any fashion or position... why wouldn't one not be able to use a parameter on the sprite x- and y-offsets? (Yes, I use(d) templates which use a parameter for virtually everythingFooBar wrote:You mean you use template parameters in the offsets? As I understood that was the thing that was not possible...
Maybe someone more familiar with the NML source code can clarify this once and for all.

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
I have no idea and actually find it a bit weird if you couldn't. But as long als the NML Documentation says that you can't, I can't be sureplanetmaker wrote:why wouldn't one not be able to use a parameter on the sprite x- and y-offsets?

Re: NML tutorial
I've removed that confusing line from the spec as it was confusing and didn't add anything.FooBar wrote:Technically you're right. But because this states that you cannot use parameters for the offsets, I simplified it a bit not to bother users with too much details. I don't see a use for calculations in offsets either for as long as you can't use parameters in them.
In the process I've completely removed the part in the tutorial about not being able to use parameters on any value. Technically you could even use the template parameters for the compression or filename arguments, although it would be even harder to find a use case for that.
Re: NML tutorial
Thanks for clearing this up, Yexo. I do have a use for parameterizing the filename in my tram track grf. Actually, it was me who requested the filename to be parameterizable in templates 
Also, there's now an introduction to callbacks and switch blocks in the tutorial![Pleased :]](./images/smilies/pleased.gif)

Also, there's now an introduction to callbacks and switch blocks in the tutorial
![Pleased :]](./images/smilies/pleased.gif)
Re: NML tutorial
Not true, so I've removed it.//return a failure result as default (this is the same as <code>return 0xFF</code>).
Re: NML tutorial
Hmmm, wrong assumption on my part.
I couldn't really find from the source what CB_FAILED does, so I (wrongly) assumed it was that.
I couldn't really find from the source what CB_FAILED does, so I (wrongly) assumed it was that.
Re: NML tutorial
Will it be a problem to call it template variable i.e.?FooBar wrote:You mean you use template parameters in the offsets? As I understood that was the thing that was not possible...
Maybe someone more familiar with the NML source code can clarify this once and for all.
I agree with you that "parameter" is confusing. I decided to rename them to "template parameter" to hopefully reduce/avoid this confusion. The remainder of the tutorial will spreak of "template parameter" and "grf parameter" where applicable, to make explicitly clear what is meant by "parameter".
Re: NML tutorial
Possibly, but then you get a similar confusion with the variables available to features, basically the variables listed here: http://newgrf-specs.tt-wiki.net/wiki/NM ... _callbacks
In programming, the proper term actually is "parameter", as the template is a user-defined "function" that accepts any number of parameters. I'm completely in favour of an unambiguous replacement, but I don't think variable is that replacement. Still open to suggestions though.
In programming, the proper term actually is "parameter", as the template is a user-defined "function" that accepts any number of parameters. I'm completely in favour of an unambiguous replacement, but I don't think variable is that replacement. Still open to suggestions though.
Re: NML tutorial
You could try argument. As far as I know it's not used anywhere else in NML-terminology and imo it's just as good as parameter.
Re: NML tutorial
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)
Who is online
Users browsing this forum: No registered users and 6 guests