Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Wed Jun 19, 2013 10:54 am

All times are UTC




Post new topic Reply to topic  [ 33 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: NML tutorial
PostPosted: Mon Aug 22, 2011 9:41 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon May 21, 2007 11:47 am
Posts: 6122
Location: The Netherlands
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.

_________________
FooBar's Tram Tracks | TransRapid Track Set | Metro Track Set | OpenGFX base graphics set | FIRS Industry Replacement Set
Dutch Tram Set | Dutch Trainset 2 | Dutch Road Furniture


Last edited by FooBar on Mon Aug 29, 2011 11:05 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Mon Aug 22, 2011 10:40 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
Once again amazing work FooBar :bow:

You seem to have switched up the -c and -u flags (-c is for cropping), so I've fixed that.


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Mon Aug 22, 2011 11:21 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon May 21, 2007 11:47 am
Posts: 6122
Location: The Netherlands
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 :)

_________________
FooBar's Tram Tracks | TransRapid Track Set | Metro Track Set | OpenGFX base graphics set | FIRS Industry Replacement Set
Dutch Tram Set | Dutch Trainset 2 | Dutch Road Furniture


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Tue Aug 23, 2011 1:30 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Thu Sep 11, 2008 7:32 am
Posts: 1029
Location: Spain
Awesome work :)

_________________
Spanish translation of OpenTTD
Extended heightmaps

Have fun, don't quarrel too much and add as many advanced settings as you can.


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Tue Aug 23, 2011 8:56 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon May 21, 2007 11:47 am
Posts: 6122
Location: The Netherlands
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 :)

_________________
FooBar's Tram Tracks | TransRapid Track Set | Metro Track Set | OpenGFX base graphics set | FIRS Industry Replacement Set
Dutch Tram Set | Dutch Trainset 2 | Dutch Road Furniture


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Tue Aug 23, 2011 9:05 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Tue Dec 03, 2002 10:36 am
Posts: 12837
Location: The Netherlands
Thank you a lot, FooBar :).

_________________
Image
Dutch Trainset for OpenTTD | Dutch Trainset Topic | Combined Roadset v0.10


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Tue Aug 23, 2011 9:38 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
Overall I can only say (again!) that you did an excellent job! I do have some comments:

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.
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/Cargotable wrote:
very NewGRF can have exactly one cargotable (but you may select from several using if/else statements).
Not true, NML limits you to exactly one cargotable, regardless of whether that cargotable is inside an if-block or not.


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Tue Aug 23, 2011 10:18 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon May 21, 2007 11:47 am
Posts: 6122
Location: The Netherlands
Hyronymus, Terkhen and Yexo, thanks for your kind words.

Yexo wrote:
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.
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).

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.
I added this as a footnote, just to be complete.

Yexo wrote:
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).
Not true, NML limits you to exactly one cargotable, regardless of whether that cargotable is inside an if-block or not.

I didn't know that. Duly noted and fixed.

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 :)

_________________
FooBar's Tram Tracks | TransRapid Track Set | Metro Track Set | OpenGFX base graphics set | FIRS Industry Replacement Set
Dutch Tram Set | Dutch Trainset 2 | Dutch Road Furniture


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Wed Aug 24, 2011 5:32 am 
Online
Tycoon
Tycoon

Joined: Wed Jan 17, 2007 12:14 am
Posts: 4614
... 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.

_________________
You might not exactly be interested in Ferion, but if you are, have fun :)


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Wed Aug 24, 2011 8:58 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon May 21, 2007 11:47 am
Posts: 6122
Location: The Netherlands
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".

_________________
FooBar's Tram Tracks | TransRapid Track Set | Metro Track Set | OpenGFX base graphics set | FIRS Industry Replacement Set
Dutch Tram Set | Dutch Trainset 2 | Dutch Road Furniture


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Wed Aug 24, 2011 10:21 am 
Online
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Wed Nov 07, 2007 10:44 pm
Posts: 7091
Location: Sol d
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 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 everything ;-) )

_________________
Image
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Wed Aug 24, 2011 10:47 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon May 21, 2007 11:47 am
Posts: 6122
Location: The Netherlands
planetmaker wrote:
why wouldn't one not be able to use a parameter on the sprite x- and y-offsets?

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 sure :P

_________________
FooBar's Tram Tracks | TransRapid Track Set | Metro Track Set | OpenGFX base graphics set | FIRS Industry Replacement Set
Dutch Tram Set | Dutch Trainset 2 | Dutch Road Furniture


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Wed Aug 24, 2011 10:52 am 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
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.
I've removed that confusing line from the spec as it was confusing and didn't add anything.
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.


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Wed Aug 24, 2011 11:07 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon May 21, 2007 11:47 am
Posts: 6122
Location: The Netherlands
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 :]

_________________
FooBar's Tram Tracks | TransRapid Track Set | Metro Track Set | OpenGFX base graphics set | FIRS Industry Replacement Set
Dutch Tram Set | Dutch Trainset 2 | Dutch Road Furniture


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Wed Aug 24, 2011 11:37 am 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
Quote:
//return a failure result as default (this is the same as <code>return 0xFF</code>).
Not true, so I've removed it.


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Wed Aug 24, 2011 11:48 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon May 21, 2007 11:47 am
Posts: 6122
Location: The Netherlands
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.

_________________
FooBar's Tram Tracks | TransRapid Track Set | Metro Track Set | OpenGFX base graphics set | FIRS Industry Replacement Set
Dutch Tram Set | Dutch Trainset 2 | Dutch Road Furniture


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Wed Aug 24, 2011 4:06 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Tue Dec 03, 2002 10:36 am
Posts: 12837
Location: The Netherlands
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".

Will it be a problem to call it template variable i.e.?

_________________
Image
Dutch Trainset for OpenTTD | Dutch Trainset Topic | Combined Roadset v0.10


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Wed Aug 24, 2011 4:49 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon May 21, 2007 11:47 am
Posts: 6122
Location: The Netherlands
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.

_________________
FooBar's Tram Tracks | TransRapid Track Set | Metro Track Set | OpenGFX base graphics set | FIRS Industry Replacement Set
Dutch Tram Set | Dutch Trainset 2 | Dutch Road Furniture


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Wed Aug 24, 2011 4:51 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
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.


Top
 Profile  
 
 Post subject: Re: NML tutorial
PostPosted: Wed Aug 24, 2011 6:32 pm 
Online
Tycoon
Tycoon

Joined: Wed Jan 17, 2007 12:14 am
Posts: 4614
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)

_________________
You might not exactly be interested in Ferion, but if you are, have fun :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 33 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000-2013 phpBB Group

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2013.
Hosted by Zernebok Hosting.