Difference between revisions of "NMLTutorial"

From TTWiki
(Added stub for difference between NFO and NML)
(Expanded the NML vs. NFO stub)
Line 7: Line 7:
   
 
==NML vs. NFO==
 
==NML vs. NFO==
  +
===Background===
NML is a high-level NewGRF language compiler which compiles nml files into newgrf files (and NFO files, if asked to do so).
 
  +
NML is a high-level NewGRF language compiler which compiles NML and LNG files into newgrf files (and NFO files, if asked to do so). Coding a NewGRF in NML is similar to writing in any other programming language except that there are no real sub-routines; you can use the usual definition and condition statements.
   
  +
===Language support===
Writing a NewGRF in NML is similar to writing in any other programming language except that there are no real sub-routines; you can use the usual definition and condition statements. Sounds impressive, maybe even threatening right? One image often says more than a thousand words so let's show the difference with two images:
 
  +
NML provides easy support for different languages in one GRF. This is achieved by creating language files (LNG). These language files follow the convention used for OpenTTD translation files. When compiling NML files a search for language files will automatically be performed. Even without providing additional translations at least one language file must be specified, called default.lng.
   
  +
===Image format support===
{| cellspacing="0" class="mainpagetable" align="left" style="background-color: ##F8EABA;" style="border: 1px solid #C0C090;"
 
  +
One of the conveniences of NML is the possibility to read other image formats, most notably [http://en.wikipedia.org/wiki/Portable_Network_Graphics PNG]. Remember though that those images still need to supply the proper 8bpp palette and are supported by the python image library.
  +
  +
===Example===
  +
Does the above sound impressive, maybe even threatening to you? One illustration often says more than a thousand words so let's show the difference with two illustrations:
  +
  +
{| cellspacing="0" class="mainpagetable" text-align="left" style="background-color: #F8EABA; border: 1px solid #C0C090;"
 
|- valign="top"
 
|- valign="top"
   
Line 36: Line 44:
 
:STR_GRF_DESCRIPTION
 
:STR_GRF_DESCRIPTION
 
|}
 
|}
 
See below for a comparison between NFO and NML with a small rail types newgrf as example. One of the convenient changes is also NML's possibility to read other image formats, most notably also png (those images still need to supply the proper 8bpp palette and are supported by the python image library). Personally I find png quite convenient as the same format can also easily be viewed in browsers (no nasty conversions anymore needed).
 
 
 
 
 
 
[[Category:NML]][[Category:Tutorials]]
 
[[Category:NML]][[Category:Tutorials]]

Revision as of 18:23, 21 June 2011

Introduction

Since june 2010 a new coding language for creating TTDpatch/OpenTTD GRF's exists: Newgrf Meta Language or NML. It differs significantly from the old way of GRF editing and although documentation is available it may still be a challenge for people interested in using NML code.

There will be detailed examples of how coding in NML works on this new TT-wiki. Make sure to check the progress of this NML tutorial regularly.

NML vs. NFO

Background

NML is a high-level NewGRF language compiler which compiles NML and LNG files into newgrf files (and NFO files, if asked to do so). Coding a NewGRF in NML is similar to writing in any other programming language except that there are no real sub-routines; you can use the usual definition and condition statements.

Language support

NML provides easy support for different languages in one GRF. This is achieved by creating language files (LNG). These language files follow the convention used for OpenTTD translation files. When compiling NML files a search for language files will automatically be performed. Even without providing additional translations at least one language file must be specified, called default.lng.

Image format support

One of the conveniences of NML is the possibility to read other image formats, most notably PNG. Remember though that those images still need to supply the proper 8bpp palette and are supported by the python image library.

Example

Does the above sound impressive, maybe even threatening to you? One illustration often says more than a thousand words so let's show the difference with two illustrations:

NFO code snippet

// Automatically generated by GRFCODEC. Do not modify!
// (Info version 7)
// Escapes: 2+ = 71 = D= = DR 2- = 70 = D+ = DF 2< = 7= = D- = DC 2> = 7! = Du* = DM 2u< = 7< = D* = DnF 2u> = 7> = Du<< = DnC
2/ = 7G = D<< = DO 2% = 7g = D& 2u/ = 7gG = D| 2u% = 7GG = Du/ 2* = 7gg = D/ 2& = 7c = Du% 2| = 7C = D% 2^ 2sto = 2s 2rst = 2r 2+ 2ror = 2rot
// Format: spritenum pcxfile xpos ypos compression ysize xsize xrel yrel
0 * 4 \d416
1 * 92 08 07 "SER0" "ÞSwedish Rails nightly-r52M" 00 "ÞSwedish rails are a replacement for the default rails" 00

NML code snippet

grf {
grfid : "SER0";
name : string(STR_GRF_NAME);
desc : string(STR_GRF_DESCRIPTION);
}

NML laguage file snippet

lang: 7F
STR_GRF_NAME  :Swedish Rails {VERSION}
STR_GRF_DESCRIPTION