Page 1 of 2
How to make a NewGRF properly ?
Posted: 25 Jan 2018 19:45
by acs121
Hey,
I've learned NML in the last days and i'd want to start with a small NewGRF.
I searched information but i didn't find where i could create a NewGRF in just one file.
Re: How to make a NewGRF properly ?
Posted: 25 Jan 2018 20:03
by Erato
https://www.tt-wiki.net/wiki/NMLTutorial/
This should explain everything you need to know about making a NewGRF in NML and compiling the code.
Start at the very top of the list. Compilation is one of the first things in the Tutorial.
Re: How to make a NewGRF properly ?
Posted: 25 Jan 2018 20:16
by acs121
I've seen this, but it still doesn't tell me how i make this directory structure in the Language Tutorial.
Re: How to make a NewGRF properly ?
Posted: 25 Jan 2018 20:32
by Gwyd
The directory structure (basically)
/(NewGRF file):
Here should be:
(NewGRF name).nml
Possibly the compiler
/(NewGRF file)/lang:
Here should be:
english.lng
(Other language).lng
/(NewGRF file)/gfx:
This is where your graphics should be, possibly sorted into sub-folders
/(NewGRF file)/sfx:
You can have sounds, but don't need them.
You can have other various sub-folders for graphics, and .pnml files. .pnml files have parts of the full .nml, but must be compiled into the (NewGRF name).nml. If you need me to clarify slightly, just ask.
Sent from my SM-G935F using Tapatalk
Re: How to make a NewGRF properly ?
Posted: 25 Jan 2018 21:19
by acs121
Can it be a normal directory ? And how to compile then the directory into a NewGRF ?
Re: How to make a NewGRF properly ?
Posted: 25 Jan 2018 21:35
by Erato
Assuming you're on Windows:
https://www.tt-wiki.net/wiki/NMLTutoria ... sing_NML_3
Just have a folder like this:

and then you can just use:
and this will give you MMT.grf. Nothing more, nothing less. You can then drop this file into C:\Users\USER\Documents\OpenTTD\newgrf
Re: How to make a NewGRF properly ?
Posted: 25 Jan 2018 21:54
by acs121
Where to get all those other files ? I only have lang and gfx.
And the GRF file is the NML file but i need to change the extension or it's something else ?
Re: How to make a NewGRF properly ?
Posted: 25 Jan 2018 23:45
by Erato
acs121 wrote:Where to get all those other files ? I only have lang and gfx.
And the GRF file is the NML file but i need to change the extension or it's something else ?
This tells me you had a total disregard for my first message and in fact did not follow the tutorial. The tutorial starts with the installation of nml, which will get you the other files.
EDIT:
https://www.tt-wiki.net/wiki/NMLTutoria ... ling_NML_3
Re: How to make a NewGRF properly ?
Posted: 26 Jan 2018 08:33
by acs121
I did get nmlc.exe before creating the topic. I simply didn't know those files were from that file.
Re: How to make a NewGRF properly ?
Posted: 26 Jan 2018 18:03
by Leanden
acs121 wrote:I did get nmlc.exe before creating the topic. I simply didn't know those files were from that file.
So youve jumped straight to the download link and ignored the rest. Go read the tutorial again.
Re: How to make a NewGRF properly ?
Posted: 26 Jan 2018 18:33
by acs121
Man, my answer was given now. Let me work, please, you that posted "I almost get the impression you are running around the forums telling everyone to do stuff for you. At some point you should really just bite the bullet and do it yourself". I'm just biting the bullet and doing it myself here, and you're complaining. Appreciate things at their just value.
Re: How to make a NewGRF properly ?
Posted: 14 Mar 2018 15:44
by acs121
Erato wrote:Assuming you're on Windows:
https://www.tt-wiki.net/wiki/NMLTutoria ... sing_NML_3
Just have a folder like this:

and then you can just use:
and this will give you MMT.grf. Nothing more, nothing less. You can then drop this file into C:\Users\USER\Documents\OpenTTD\newgrf
I did type nmlc -c --grf ***.grf ***.nml and it told me this :
Usage : nmlc [options] <filename>
Where <filename> is the nml file to parse
nmlc : error : Error : only a single nml file can be read per run
I give you the screen of the GRF file.
Re: How to make a NewGRF properly ?
Posted: 14 Mar 2018 16:00
by andythenorth
acs121 wrote:I did type nmlc -c --grf ***.grf ***.nml and it told me this :
Don't use ***
Give the actual nml filename.
nmlc : error : Error : only a single nml file can be read per run
This is saying "don't use ***".
Re: How to make a NewGRF properly ?
Posted: 14 Mar 2018 16:12
by acs121
I am using *** instead of the nml file name/GRF file name.
Re: How to make a NewGRF properly ?
Posted: 14 Mar 2018 16:46
by Quast65
Have you read this in the tutorial:
Code: Select all
Note that if you have any spaces in a directory or file name, you need to enclose that complete path or filename in double quotes, e.g.: cd "D:\Users\Username\My Documents\mygrf".
It is therefore recommended not to have any spaces.
Looking at the screenshot of your setup I can see a space in the .nml itself and maybe you also have spaces in the path/directory to it...
Try using underscores: _ Rather than spaces.
Re: How to make a NewGRF properly ?
Posted: 14 Mar 2018 17:13
by acs121
Huge thanks Quast. You saved me.

Re: How to make a NewGRF properly ?
Posted: 14 Mar 2018 18:52
by acs121
Uh, now it gives me this :
C:\Users\User\Desktop\Alstom RegioCitadis>nmlc -c --grf AlstomRegioCitadis.grf AlstomRegioCitadis.nml
[Knmlc ERROR: nmlc: An internal error has occurred:
nmlc-version: v6379:afad0c76c40b from 2017-06-19
Error: (ValueError) "Unknown format code 'r' for object of type 'str'".
Command: ['nmlc', '-c', '--grf', 'AlstomRegioCitadis.grf', 'AlstomRegioCitadis.nml']
Location: File "nml\grfstrings.py", line 971, in handle_grflangid
Re: How to make a NewGRF properly ?
Posted: 14 Mar 2018 20:29
by Quast65
I am guessing now...
What happens if you also remove the space in the directory name?
(this may affect certain paths to for example gfx in your .nml, be sure to change those too then if necessary)
Re: How to make a NewGRF properly ?
Posted: 14 Mar 2018 20:36
by acs121
It didn't do much things.
Re: How to make a NewGRF properly ?
Posted: 15 Mar 2018 21:28
by rowdog
My guess would be that there is an issue with your .lng file, in particular, the first line that defines the grflangid. Looking around in the nmlc code...
Code: Select all
def handle_grflangid(self, data, pos):
"""
Handle a 'grflangid' pragma.
@param data: Data of the pragma.
@type data: C{str}
"""
if self.langid is not None:
raise generic.ScriptError("grflangid already set", pos)
lang_text = data[1].strip()
value = LANG_NAMES.get(lang_text)
if value is None:
try:
value = int(lang_text, 16)
except ValueError:
raise generic.ScriptError("Invalid grflangid {:r}".format(lang_text), pos)
if value < 0 or value >= 0x7F:
raise generic.ScriptError("Invalid grflangid", pos)
self.langid = value
self.check_expected_plural(None)
Line 971 is
Code: Select all
raise generic.ScriptError("Invalid grflangid {:r}".format(lang_text), pos)
. What I think is happening here is that your grflangid isn't valid and nmlc really wants to tell you that your grflangid is bad but the error message raises another exception about the "{:r}" which is what gets reported to you.