Yet another NML questions thread.
Moderator: Graphics Moderators
Yet another NML questions thread.
Hi all
Yet another newbie NML coder here. I've experience with NFO, but NML is something that's completely foreign to me. However, I've decided to take it all in my stride and hop in and see what I can do with it.
The first wall I've hit is with the usage of articulated vehicles. In the same way I once used NFO to do this, I automatically started to write a switch block to define the different parts. This works fine, but the wiki says this is an old way to do callbacks and shouldn't be done unless one has a good reason. So I'm just wondering, how does one go about writing an articulated vehicle callback using the "new" style?
Thanks
Lachlan
Yet another newbie NML coder here. I've experience with NFO, but NML is something that's completely foreign to me. However, I've decided to take it all in my stride and hop in and see what I can do with it.
The first wall I've hit is with the usage of articulated vehicles. In the same way I once used NFO to do this, I automatically started to write a switch block to define the different parts. This works fine, but the wiki says this is an old way to do callbacks and shouldn't be done unless one has a good reason. So I'm just wondering, how does one go about writing an articulated vehicle callback using the "new" style?
Thanks
Lachlan
Formerly known as Lachie
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: Yet another NML questions thread.
The way FooBar layed it out in the tutorial: http://www.tt-wiki.net/wiki/NMLTutorial ... ticulation
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: Yet another NML questions thread.
okay, so this is the "new" way of doing it? For some reason, the documentation lead me to believe that it was something simple that went in the "graphics" section alone. I have done it in the right way, after all. 

Formerly known as Lachie
Re: Yet another NML questions thread.
The old way is this:
The new way is this:
Basically you don't mess with callback numbers yourself but let nml handle that. This also means you can't forget to add a bit to the callback flags in your action0 (=property-block) anymore. Last but not least the code is smaller without losing clarity.
Code: Select all
switch(..., cb_articulated) {
...
}
switch (.., switch_cbs, callback_number) {
VEH_CB_ARTICULATED_PARTS: cb_articulated;
normal_graphics;
}
item {
property {
callbacks: bitmask(VEH_CBF_ARTICULATED_PARTS);
}
graphics {
default: switch_cbs;
}
}
Code: Select all
switch(..., cb_articulated) {
...
}
item {
graphics {
articulated_parts: cb_articulated;
default: normal_graphics;
}
}
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: Yet another NML questions thread.
Well, the "new" way is to call the callbacks from the graphics section. In the simple cases you could return the value directly there (like if you only have one text, you might write
or in a case where you need to make a few decisions you link there to a switch dedicated to that callback:
or of course link to a certain switch section. The "new" thing about this is that the callback is not treated in the same switch tree as the graphics (real sprites, spritesets) are decided (as Yexo explained much more verbosely)
Code: Select all
graphics {
additional_text: string(STR_EXTRA_VEHICLE_XXX_TEXT);
}
Code: Select all
graphics {
additional_text: decide_extra_text_vehicle_xxx;
}
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: Yet another NML questions thread.
That's missing a return, isn't it?planetmaker wrote:Code: Select all
graphics { additional_text: string(STR_EXTRA_VEHICLE_XXX_TEXT); }
Re: Yet another NML questions thread.
Yes and No.
According to the specs there should be a return there, but for the compiler it's been optional for quite some time now. Please keep the return there, as in the future it might no longer be optional.
According to the specs there should be a return there, but for the compiler it's been optional for quite some time now. Please keep the return there, as in the future it might no longer be optional.
Who is online
Users browsing this forum: No registered users and 17 guests