Yet another NML questions thread.

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

Moderator: Graphics Moderators

Post Reply
BobDendry
Tycoon
Tycoon
Posts: 2215
Joined: 06 May 2004 09:10
Location: Sydney

Yet another NML questions thread.

Post by BobDendry »

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
Formerly known as Lachie
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Yet another NML questions thread.

Post by planetmaker »

The way FooBar layed it out in the tutorial: http://www.tt-wiki.net/wiki/NMLTutorial ... ticulation
BobDendry
Tycoon
Tycoon
Posts: 2215
Joined: 06 May 2004 09:10
Location: Sydney

Re: Yet another NML questions thread.

Post by BobDendry »

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
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Yet another NML questions thread.

Post by Yexo »

The old way is this:

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;
  }
}
The new way is this:

Code: Select all

switch(..., cb_articulated) {
...
}

item {
  graphics {
    articulated_parts: cb_articulated;
    default: normal_graphics;
  }
}
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.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Yet another NML questions thread.

Post by planetmaker »

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

Code: Select all

graphics {
  additional_text: string(STR_EXTRA_VEHICLE_XXX_TEXT);
}
or in a case where you need to make a few decisions you link there to a switch dedicated to that callback:

Code: Select all

graphics {
  additional_text: decide_extra_text_vehicle_xxx;
}
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)
Michi_cc
OpenTTD Developer
OpenTTD Developer
Posts: 619
Joined: 14 Jun 2004 23:27
Location: Berlin, Germany
Contact:

Re: Yet another NML questions thread.

Post by Michi_cc »

planetmaker wrote:

Code: Select all

graphics {
  additional_text: string(STR_EXTRA_VEHICLE_XXX_TEXT);
}
That's missing a return, isn't it?
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Yet another NML questions thread.

Post by Yexo »

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

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 17 guests