NML - a Newgrf Meta Language

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: NML - a Newgrf Meta Language

Post by Hirundo »

planetmaker wrote:And... did you try with "the latest" nightly (yesterday / today)?
It seems my local 'trunk' copy wasn't too up to date either :D
Create your own NewGRF? Check out this tutorial!
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

FooBar wrote:Sorry to cause all this fuzz about something that already was fixed, but thanks very much for your time trying to help me out here (and eventually helping me out)! :D
No worries. I remembered dimmly that commit, so I thought I just ask :-)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

Since grf v8 I think there is no reason anymore to hardcode prop 15 to 0xFF, it can now actually be a default cargo. As such it's a bug in NML as well (although that was not what you experienced) :p.
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: NML - a Newgrf Meta Language

Post by FooBar »

Yexo wrote:it can now actually be a default cargo
But what would you set it to in my case?
It's a passengers-only train, but I don't have passengers in my cargotable.

Or are you saying that NML should allow setting a default cargo by the coder (or at their discretion, the first refittable), basically what akasoft wanted to do a number of posts back?
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

If I use code

Code: Select all

switch (FEAT_TRAINS, SELF, _2m62u_cargo_subtype_text2,
  current_year >= 1990)
{
  1: string(STR_REFIT_V3);
  return CB_RESULT_NO_TEXT;
}

switch (FEAT_TRAINS, SELF, _2m62u_cargo_subtype_text,
  cargo_subtype)
{
  0: string(STR_REFIT_V1);
  1: string(STR_REFIT_V2);
  2: _2m62u_cargo_subtype_text2;
  3: string(STR_REFIT_V4);
  4: string(STR_REFIT_V5);
  5: string(STR_REFIT_V6);
  6: string(STR_REFIT_V7);
  7: string(STR_REFIT_V8);
  8: string(STR_REFIT_V9);
  return CB_RESULT_NO_TEXT;
}
it work normally, but if I try to simplify the code so

Code: Select all

switch (FEAT_TRAINS, SELF, _2m62u_cargo_subtype_text,
  cargo_subtype)
{
  0: string(STR_REFIT_V1);
  1: string(STR_REFIT_V2);
  2: return ((current_year >= 1990) ? string(STR_REFIT_V3) : CB_RESULT_NO_TEXT);
  3: string(STR_REFIT_V4);
  4: string(STR_REFIT_V5);
  5: string(STR_REFIT_V6);
  6: string(STR_REFIT_V7);
  7: string(STR_REFIT_V8);
  8: string(STR_REFIT_V9);
  return CB_RESULT_NO_TEXT;
}
then I receive the error when try to refit cargo
cb19_error.png
cb19_error.png (2.95 KiB) Viewed 3256 times
Why, what's wrong? I cannot use syntax "() ? () : ()" here?
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

akasoft wrote:(...)Why, what's wrong? I cannot use syntax "() ? () : ()" here?
While I agree that it would be nice, if it works, the NML manual doesn't tell that it is correct: http://newgrf-specs.tt-wiki.net/wiki/NML:Switch

what I'd try is to use temporary registers:

Code: Select all

switch (FEAT_TRAINS, SELF, _2m62u_cargo_subtype_text,
  [STORE_TEMP( (current_year >= 1990) ? string(STR_REFIT_V3) : CB_RESULT_NO_TEXT, 0), cargo_subtype])
{
  0: string(STR_REFIT_V1);
  1: string(STR_REFIT_V2);
  2: return LOAD_TEMP(0);
  3: string(STR_REFIT_V4);
  4: string(STR_REFIT_V5);
  5: string(STR_REFIT_V6);
  6: string(STR_REFIT_V7);
  7: string(STR_REFIT_V8);
  8: string(STR_REFIT_V9);
  return CB_RESULT_NO_TEXT;
}
Note that I haven't tested it.

Note also, that you should always use 'return string(...)' instead of just 'string(...)'. The way you write without return does work indeed, but it's undocumented and might cease to work without notice (yes, I'm a bad example there, too. My newgrfs have that code without return as well :-P )
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

I thought that "expression" include "()?():()". :)

Thank you for the example of the temporary registers. And notes.

I try to use this hack (considering that CB_RESULT_NO_TEXT == 0x400)

Code: Select all

  2: return ((current_year >= 1990) ? string(STR_REFIT_V3) : CB_RESULT_NO_TEXT) & 0x7FF;
it work normally. This is malicious hack or not? :)

Variant of the temporary registers not work and receive the same error message.
I think, the key point here - "string(..)" and "& 0x7FF". Function string(..) has the return value with setted high bits. Or their set the "()?():()". Or "return" not work properly.

My version of "()?():()" I like more than.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

akasoft wrote:I thought that "expression" include "()?():()". :)
You're right.
akasoft wrote:

Code: Select all

  2: return ((current_year >= 1990) ? string(STR_REFIT_V3) : CB_RESULT_NO_TEXT) & 0x7FF;
it work normally. This is malicious hack or not? :)
Malicious certainly not. But it looks wrong to me... on first look the &0x7FF imho shouldn't be required.
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

Add.
Code

Code: Select all

switch (FEAT_TRAINS, SELF, _2m62u_cargo_subtype_text,
[
  STORE_TEMP(string(STR_REFIT_V3), 0),
  cargo_subtype
]
)
{
  0: string(STR_REFIT_V1);
  1: string(STR_REFIT_V2);
  2: return LOAD_TEMP(0);
  3: string(STR_REFIT_V4);
  4: string(STR_REFIT_V5);
  5: string(STR_REFIT_V6);
  6: string(STR_REFIT_V7);
  7: string(STR_REFIT_V8);
  8: string(STR_REFIT_V9);
  return CB_RESULT_NO_TEXT;
}
also not work and receive the error message.
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

If used

Code: Select all

  STORE_TEMP(string(STR_REFIT_V3) & 0x7FF, 0),
then has no error and it work.

nmlc.exe r1792
openttd r23840 trunk x86
Windows 7 x64
Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: NML - a Newgrf Meta Language

Post by Hirundo »

[quote="akasoft"]

Code: Select all

 return ((current_year >= 1990) ? string(STR_REFIT_V3) : CB_RESULT_NO_TEXT);
The () ? () : () operator is designed to operate on numeric values only. A string() is not a number, although it NML tries to make sense of it, it fails quite badly.

For now, don't use ?: on strings. In the future, NML should be amended to either properly handle this case or throw an error. I have filed an NML ticket (3610) about this
Create your own NewGRF? Check out this tutorial!
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

Hirundo wrote:For now, don't use ?: on strings.
Why? First, it is very convenient, is easy to do. Secondly, the function string () returns a number.
In terms of the openttd, it has no strings, only numbers.

Please, do not disable this feature. There's just need to make the return value into the valid value. Which I did with using "& 0x7FF".

Add: At NML (NewGRF) are not so many opportunities for programming, so they throw away.
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

How to use procedure call in NML?

If I use code:

Code: Select all

switch (FEAT_TRAINS, SELF, l_e_purchase_speed,
  current_year >= 1920)
{
  1: return 120;
  return 105;
}

switch (FEAT_TRAINS, SELF, l_e_speed,
[
  STORE_TEMP(var[0x7E, 0, 0, l_e_purchase_speed] + last_computed_result, 0),
  position_in_consist == 0 ? LOAD_TEMP(0) : LOAD_TEMP(0) * 85 / 100
])
{
  return;
}
then receive nmlc error: "nmlc: "xussr.nml", line 1263: All parts of a variable access must be integers.".

I want to use block l_e_purchase_speed via procedure call.
What is the correct syntax to use it?
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

akasoft wrote:What is the correct syntax to use it?
There is no syntax for it yet, it's currently unsupported.
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

It will be supported? Is planned?
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

Yes, but it has been that way for a while now. Don't count on it anytime soon.
oberhümer
Tycoon
Tycoon
Posts: 1283
Joined: 23 Oct 2009 19:35
Location: Here and there, sometime or another

Re: NML - a Newgrf Meta Language

Post by oberhümer »

Is is possible to force a 32 bpp blitter (or "set it as preferred") using NML?
--- Licenses: GNU LGPL, version 2 or newer, code and graphics. CC-By-SA, graphics, alternatively. If you're using any, I'd like to hear about it --- Call them "track types" ---
--- Mostly inactive developer for: NuTracks - Central European Train Set --- Running/compiling for: Linux (x86) - Android - Windows (32/64 bit) ---

--- Need a file packer? 7-Zip --- BOINC - use your computing power to benefit science --- Block trackers, not ads --- Unix in dispersible pellets, the formula for the future. ---
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: NML - a Newgrf Meta Language

Post by FooBar »

You can never force that, also not in NFO. What this does is request the game for a 32bpp blitter, but there's no guarantee that you'll get one.

Either way, NML sets the appropriate action 14 entry automatically if you define 32bpp sprites in your NML code. See http://dev.openttdcoop.org/projects/nml ... 78ee234135
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: NML - a Newgrf Meta Language

Post by FooBar »

Sorry for the doublepost, but I was wondering what the best approach is for livery refits on an engine that isn't supposed to have a capacity.

I guess I'm supposed to give it a capacity and then override that again with the cargo_capacity callback, but I can't quite figure it out how it's all supposed to come together.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: NML - a Newgrf Meta Language

Post by frosch »

Yes, you need to set the property to a non-zero value, and set a zero capacity with the callback.
You will also have to decide for some cargo type.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 24 guests