How to make a NewGRF properly ?

Discuss, get help with, or post new graphics for TTDPatch and OpenTTD, using the NewGRF system, here. Graphics for plain TTD also acceptable here.

Moderator: Graphics Moderators

User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

How to make a NewGRF properly ?

Post 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.
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: How to make a NewGRF properly ?

Post 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.
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

Re: How to make a NewGRF properly ?

Post by acs121 »

I've seen this, but it still doesn't tell me how i make this directory structure in the Language Tutorial.
User avatar
Gwyd
Chief Executive
Chief Executive
Posts: 721
Joined: 17 Apr 2017 16:52
Location: Western Ile-de-France Region

Re: How to make a NewGRF properly ?

Post 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
User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

Re: How to make a NewGRF properly ?

Post by acs121 »

Can it be a normal directory ? And how to compile then the directory into a NewGRF ?
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: How to make a NewGRF properly ?

Post by Erato »

Assuming you're on Windows:
https://www.tt-wiki.net/wiki/NMLTutoria ... sing_NML_3

Just have a folder like this:
Image
and then you can just use:

Code: Select all

nmlc -c --grf MMT.grf MMT.nml
and this will give you MMT.grf. Nothing more, nothing less. You can then drop this file into C:\Users\USER\Documents\OpenTTD\newgrf
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

Re: How to make a NewGRF properly ?

Post 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 ?
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: How to make a NewGRF properly ?

Post 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
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

Re: How to make a NewGRF properly ?

Post by acs121 »

I did get nmlc.exe before creating the topic. I simply didn't know those files were from that file.
User avatar
Leanden
Tycoon
Tycoon
Posts: 2613
Joined: 19 Mar 2009 19:25
Location: Kent

Re: How to make a NewGRF properly ?

Post 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.
Image
User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

Re: How to make a NewGRF properly ?

Post 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.
User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

Re: How to make a NewGRF properly ?

Post 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:
Image
and then you can just use:

Code: Select all

nmlc -c --grf MMT.grf MMT.nml
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.
Attachments
2018-03-14 (14).png
(79.77 KiB) Not downloaded yet
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5656
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: How to make a NewGRF properly ?

Post 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 ***".
User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

Re: How to make a NewGRF properly ?

Post by acs121 »

I am using *** instead of the nml file name/GRF file name.
User avatar
Quast65
Tycoon
Tycoon
Posts: 2654
Joined: 09 Oct 2011 13:51
Location: The Netherlands

Re: How to make a NewGRF properly ?

Post 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.
Projects: http://www.tt-forums.net/viewtopic.php?f=26&t=57266
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959
Scenario of The Netherlands: viewtopic.php?f=60&t=87604

Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016, oct 2020
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.
User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

Re: How to make a NewGRF properly ?

Post by acs121 »

Huge thanks Quast. You saved me. :bow:
User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

Re: How to make a NewGRF properly ?

Post 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
User avatar
Quast65
Tycoon
Tycoon
Posts: 2654
Joined: 09 Oct 2011 13:51
Location: The Netherlands

Re: How to make a NewGRF properly ?

Post 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)
Projects: http://www.tt-forums.net/viewtopic.php?f=26&t=57266
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959
Scenario of The Netherlands: viewtopic.php?f=60&t=87604

Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016, oct 2020
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.
User avatar
acs121
Tycoon
Tycoon
Posts: 1956
Joined: 03 Nov 2017 18:57
Location: Courbevoie, near Paris, France

Re: How to make a NewGRF properly ?

Post by acs121 »

It didn't do much things.
rowdog
Engineer
Engineer
Posts: 67
Joined: 24 May 2017 12:51
Location: East Texas

Re: How to make a NewGRF properly ?

Post 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.
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: No registered users and 17 guests