It seems my local 'trunk' copy wasn't too up to date eitherplanetmaker wrote:And... did you try with "the latest" nightly (yesterday / today)?
NML - a Newgrf Meta Language
Moderator: Graphics Moderators
Re: NML - a Newgrf Meta Language
Create your own NewGRF? Check out this tutorial!
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: NML - a Newgrf Meta Language
No worries. I remembered dimmly that commit, so I thought I just askFooBar 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)!
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: NML - a Newgrf Meta Language
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) .
Re: NML - a Newgrf Meta Language
But what would you set it to in my case?Yexo wrote:it can now actually be a default cargo
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?
Re: NML - a Newgrf Meta Language
If I use code
it work normally, but if I try to simplify the code so
then I receive the error when try to refit cargo
Why, what's wrong? I cannot use syntax "() ? () : ()" here?
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;
}
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;
}
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: NML - a Newgrf Meta Language
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:Switchakasoft wrote:(...)Why, what's wrong? I cannot use syntax "() ? () : ()" here?
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 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 )
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: NML - a Newgrf Meta Language
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)
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.
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;
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.
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: NML - a Newgrf Meta Language
You're right.akasoft wrote:I thought that "expression" include "()?():()".
Malicious certainly not. But it looks wrong to me... on first look the &0x7FF imho shouldn't be required.akasoft wrote:it work normally. This is malicious hack or not?Code: Select all
2: return ((current_year >= 1990) ? string(STR_REFIT_V3) : CB_RESULT_NO_TEXT) & 0x7FF;
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: NML - a Newgrf Meta Language
Add.
Code
also not work and receive the error message.
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;
}
Re: NML - a Newgrf Meta Language
If used
then has no error and it work.
nmlc.exe r1792
openttd r23840 trunk x86
Windows 7 x64
Code: Select all
STORE_TEMP(string(STR_REFIT_V3) & 0x7FF, 0),
nmlc.exe r1792
openttd r23840 trunk x86
Windows 7 x64
Re: NML - a Newgrf Meta Language
[quote="akasoft"]
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
Code: Select all
return ((current_year >= 1990) ? string(STR_REFIT_V3) : CB_RESULT_NO_TEXT);
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!
Re: NML - a Newgrf Meta Language
Why? First, it is very convenient, is easy to do. Secondly, the function string () returns a number.Hirundo wrote:For now, don't use ?: on strings.
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.
Re: NML - a Newgrf Meta Language
How to use procedure call in NML?
If I use code:
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?
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;
}
I want to use block l_e_purchase_speed via procedure call.
What is the correct syntax to use it?
Re: NML - a Newgrf Meta Language
There is no syntax for it yet, it's currently unsupported.akasoft wrote:What is the correct syntax to use it?
Re: NML - a Newgrf Meta Language
It will be supported? Is planned?
Re: NML - a Newgrf Meta Language
Yes, but it has been that way for a while now. Don't count on it anytime soon.
-
- Tycoon
- Posts: 1283
- Joined: 23 Oct 2009 19:35
- Location: Here and there, sometime or another
Re: NML - a Newgrf Meta Language
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. ---
--- 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. ---
Re: NML - a Newgrf Meta Language
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
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
Re: NML - a Newgrf Meta Language
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.
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.
Re: NML - a Newgrf Meta Language
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.
You will also have to decide for some cargo type.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Who is online
Users browsing this forum: No registered users and 24 guests