Changing sounds using callbacks

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

Moderator: Graphics Moderators

Post Reply
AndyLandy
Engineer
Engineer
Posts: 30
Joined: 10 Sep 2008 20:09

Changing sounds using callbacks

Post by AndyLandy »

I'd like to be able to change the sound effects of some vehicles in the GRF I'm working on, but I can't seem to make it work.

Whenever I add property 1E with value 80 in Action0, OpenTTD gives me a NewGRF error stating "read past end of pseudo-sprite" and a sprite number, which coincides with the aforementioned Action0 pseudo-sprite. I've also set property 12 to FD, which seemed to be the advice of the tutorial I was following.

The Action2 lines I've added to the file are as follows:

Code: Select all

    0 * 0    02 03 03 81 10 00 FF    01 3B 80    01    01 00 00
    0 * 0    02 03 04 85 0C 00 FF FF 01 01 00 33 00 33 00 00 00
3B is an arbitrary sound I picked from TTD that I'd like to play. The set-IDs are 03 and 04 since I've already got a couple of additional Action2s going on. I can't simply set property 12 in Action0 as it doesn't work for helicopters.

All the rest of the code works (but I can provide other chunks if necessary)
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Changing sounds using callbacks

Post by PikkaBird »

You've added another property to your action 0. Did you increase the value of <Num-props> accordingly? :)

Your callback looks fine, but obviously without the bit set in property 14 (14, not 1E) it won't work.

Edit: I assumed you are talking aircraft, since you said " it doesn't work for helicopters". The properties are different for different types of vehicle. Properties 12 (Sprite (FF for new graphics)) and 1E (Callback flags bit mask), as you have described them, are for trains; the equivalent for aircraft are 08 and 14.

http://newgrf-specs.tt-wiki.net/wiki/Ac ... les/Planes
AndyLandy
Engineer
Engineer
Posts: 30
Joined: 10 Sep 2008 20:09

Re: Changing sounds using callbacks

Post by AndyLandy »

PikkaBird wrote:You've added another property to your action 0. Did you increase the value of <Num-props> accordingly? :)

Your callback looks fine, but obviously without the bit set in property 14 (14, not 1E) it won't work.

Edit: I assumed you are talking aircraft, since you said " it doesn't work for helicopters". The properties are different for different types of vehicle. Properties 12 (Sprite (FF for new graphics)) and 1E (Callback flags bit mask), as you have described them, are for trains; the equivalent for aircraft are 08 and 14.

http://newgrf-specs.tt-wiki.net/wiki/Ac ... les/Planes
I remembered num-props, but you're quite right, the tutorial I was following was for trains and I hadn't realised the numbers would be different for aircraft. I've changed that, and now the GRF loads and doesn't give me errors, but I'm still hearing the default helicopter sound, not the one I'm trying to reference in the callback.

The code I'm using for the helicopter is as follows:

Code: Select all

  573 * 4    01 03 01 08
  574 sprites/OSP_v0.png  8bpp  386 1176   39   20  -17   -7 normal chunked
  575 sprites/OSP_v0.png  8bpp  434 1176   35   16  -14   -5 normal chunked
  576 sprites/OSP_v0.png  8bpp  482 1176   31   22  -14   -9 normal chunked
  577 sprites/OSP_v0.png  8bpp  530 1176   36   22  -19  -10 normal chunked
  578 sprites/OSP_v0.png  8bpp  578 1176   39   26  -17  -14 normal chunked
  579 sprites/OSP_v0.png  8bpp  626 1176   33   22  -11  -11 normal chunked
  580 sprites/OSP_v0.png  8bpp  674 1176   31   22   -9   -9 normal
  581 sprites/OSP_v0.png  8bpp  722 1176   34   16  -13   -5 normal chunked
  582 * 9    02 03 00 01 01 00 00 00 00
   // Aircraft type label callback.  \/  00=Copter; 01=Small; 02=Large; 03=VTOL
  583 * 14   02 03 01 81 0C 00 FF 01 03 80 23 23 00 00
  584 * 10   03 03 01 28 01 FF 01 00 01 00

   // Sound callback
  585 * 14   02 03 02 81 10 00 FF    01 46 80    01    01 00 00
  586 * 17   02 03 03 85 0C 00 FF FF 01 01 00 33 00 33 00 00 00

   // Invisible rotor sprites for VTOL aircraft.
  587 * 4    01 03 01 04
  588 sprites/trg2.png  8bpp  274 12536   17   11   -8   -5 normal chunked
  589 sprites/trg2.png  8bpp  306 12536   25    9  -12   -4 normal
  590 sprites/trg2.png  8bpp  338 12536   21   11  -10   -5 normal
  591 sprites/trg2.png  8bpp  370 12536   17   11   -8   -5 normal
  592 * 9    02 03 04 01 01 00 00 00 00
  593 * 7    03 03 81 28 00 04 00

  594 * 20   04 03 7F 01 28 "Sample Vehicle" 00
  595 * 39   00 03 0F 01 28          // Model no
                      03 15          // Vehicle Life
                      04 18          // Model Life
                      06 0F          // Climate
                      08 FF          // New Gfx
                      09 00          // 02=plane, 00=helicopter
                      0A 00          // 00=small, 01=large
                      0B 16          // Cost
                      0C 26          // Speed (*8)
                      0D 7F          // Acceleration
                      0E 0F          // Running Cost (*~£337) (default *~£42)
                      0F 5F 00       // Passenger Capacity
                      11 23          // Mail Capacity
                      14 80          // Enable Sound callback
                      15 01          // Refit cost
                      1A 3F 55 0B 00 // Date of introduction
Open to suggestions. Also, I'm not sure what best practice is around ordering of Action2 and Action3s, particularly when you're using multiple callbacks. I've noticed some odd results when I move things around.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Changing sounds using callbacks

Post by PikkaBird »

One of these things is not like the other... ;)
585 * 14 02 03 02 81 10 00 FF 01 46 80 01 01 00 00
586 * 17 02 03 03 85 0C 00 FF FF 01 01 00 33 00 33 00 00 00
If you're not using renum (included with grfcodec), use renum. :)
AndyLandy wrote:Open to suggestions. Also, I'm not sure what best practice is around ordering of Action2 and Action3s, particularly when you're using multiple callbacks. I've noticed some odd results when I move things around.
Ordering doesn't matter, just make sure you're not returning results when you don't mean to. :) If that doesn't make sense, show me an example of code that produces "odd results" and I will explain what it's doing.
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: Changing sounds using callbacks

Post by michael blunck »

AndyLandy wrote: I'm still hearing the default helicopter sound, not the one I'm trying to reference in the callback.

Code: Select all

   // Aircraft type label callback.  \/  00=Copter; 01=Small; 02=Large; 03=VTOL
  583 * 14   02 03 01 81 0C 00 FF 01 03 80 23 23 00 00
  584 * 10   03 03 01 28 01 FF 01 00 01 00

   // Sound callback
  585 * 14   02 03 02 81 10 00 FF    01 46 80    01    01 00 00
  586 * 17   02 03 03 85 0C 00 FF FF 01 01 00 33 00 33 00 00 00
Your sound CB is nowhere being accessed inside the "chain of control". Should be something like this:

Code: Select all

  583 * 14   02 03 02 81 10 00 FF    01 46 80    01    01 00 00

  584 * 14   02 03 01 81 0C 00 FF 01
		03 80 23 23 // text CB
		02 00 33 33 // sound Cb
		00 00

  585 * 10   03 03 01 28 01 FF 01 00 01 00
regards
Michael
Image
AndyLandy
Engineer
Engineer
Posts: 30
Joined: 10 Sep 2008 20:09

Re: Changing sounds using callbacks

Post by AndyLandy »

PikkaBird wrote:One of these things is not like the other... ;)
585 * 14 02 03 02 81 10 00 FF 01 46 80 01 01 00 00
586 * 17 02 03 03 85 0C 00 FF FF 01 01 00 33 00 33 00 00 00
OK, I'd moved some Action2s around and not updated all the numbers accordingly. 02 is correct. (00 is the actual new graphics, 01 is the purchase window text override), however it looks like there's more to the problem...
PikkaBird wrote:If you're not using renum (included with grfcodec), use renum. :)

Ordering doesn't matter, just make sure you're not returning results when you don't mean to. :) If that doesn't make sense, show me an example of code that produces "odd results" and I will explain what it's doing.
...Didn't know about that one. Just ran it on my GRF and all manner of errors have been reported. I'm getting "//!!Warning (100): Default ID appears earlier in sprite." before every vehicle Action3 and "//!!Error (85): This livery override action 3 does not follow a standard action 3." where I've added my 'invisible' rotors. It's not said anything about the sound callback, but that isn't working yet either (although it wouldn't surprise me if that's in part due to the other craziness in the file)

Do I have to declare a separate Action2 for every vehicle I want to change the sound for, or can it be done globally?

Thanks for your support on this so far. Eventually I'll understand how it all fits together. :)
michael blunck wrote:Your sound CB is nowhere being accessed inside the "chain of control". Should be something like this:
OK, that might be at the root of my problems. What determines the "chain of control"? Is it the set-ids of the VarAction2s, or do they all have to reference each other? I haven't yet been able to fully discern how that all fits together yet.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Changing sounds using callbacks

Post by PikkaBird »

michael blunck wrote: regards
Michael
Right, I didn't notice that, it's below the action 3. :) I think Mr Landy needs to ground himself in exactly how the action 2 chain works. :)
AndyLandy wrote: I'm getting "//!!Warning (100): Default ID appears earlier in sprite." before every vehicle Action3
That's because.. the default ID appears earlier in the sprite. :) This isn't really a problem, just a warning that you may have mistyped something. If you want things to stay as they are but don't want renum giving you messages about it, put

Code: Select all

// @@WARNING DISABLE 100
somewhere near the top of your NFO.
Do I have to declare a separate Action2 for every vehicle I want to change the sound for, or can it be done globally?
It can be done globally, but it's more sensible to do it for each vehicle.

May I suggest cutting out this one vehicle into a separate grf, posting the entire NFO, and we'll work from there. :)
AndyLandy
Engineer
Engineer
Posts: 30
Joined: 10 Sep 2008 20:09

Re: Changing sounds using callbacks

Post by AndyLandy »

PikkaBird wrote:May I suggest cutting out this one vehicle into a separate grf, posting the entire NFO, and we'll work from there. :)
Wise words...

Code: Select all

// Automatically generated by GRFCODEC. Do not modify!
// (Info version 32)
// Escapes: 2+ 2- 2< 2> 2u< 2u> 2/ 2% 2u/ 2u% 2* 2& 2| 2^ 2sto = 2s 2rst = 2r 2psto 2ror = 2rot 2cmp 2ucmp 2<< 2u>> 2>>
// Escapes: 71 70 7= 7! 7< 7> 7G 7g 7gG 7GG 7gg 7c 7C
// Escapes: D= = DR D+ = DF D- = DC Du* = DM D* = DnF Du<< = DnC D<< = DO D& D| Du/ D/ Du% D%
// Format: spritenum imagefile depth xpos ypos xsize ysize xrel yrel zoom flags
    0 * 4    19 00 00 00

    1 * 82   08 06 AA BB CC DD
"Let's build a helicopter!" 00 "Chaining VarAction2s together for fun and profit!" 00

    2 * 7    00 08 01 01 2D 08 0B  // Crank up aircraft running-cost multiplier by 8.

    3 * 102  04 03 81 04 00 D0 98 "Aircraft Type: " 8A "Helicopter" 00 // D0 00
                               98 "Aircraft Type: " 8A "Small"      00 // D0 01
                               98 "Aircraft Type: " 8A "Large"      00 // D0 02
                               98 "Aircraft Type: " 8A "VTOL"       00 // D0 03

    4 * 4    01 03 01 08
    5 sprites/OSP_v0.png  8bpp  594 1176   39   20  -17   -7 normal chunked
    6 sprites/OSP_v0.png  8bpp  642 1176   35   16  -14   -5 normal chunked
    7 sprites/OSP_v0.png  8bpp  690 1176   31   22  -14   -9 normal chunked
    8 sprites/OSP_v0.png  8bpp  738 1176   36   22  -19  -10 normal chunked
    9 sprites/OSP_v0.png  8bpp    2 1224   39   26  -17  -14 normal chunked
   10 sprites/OSP_v0.png  8bpp   50 1224   33   22  -11  -11 normal chunked
   11 sprites/OSP_v0.png  8bpp   98 1224   31   22   -9   -9 normal
   12 sprites/OSP_v0.png  8bpp  146 1224   34   16  -13   -5 normal chunked
   13 * 9    02 03 00 01 01 00 00 00 00

// Sound callback (read var10, play sound 46 on event 01)
   14 * 14   02 03 02 81 10 00 FF    01 46 80    01    01 00 00

   15 * 18   02 03 01 81 0C 00 FF 02
      03 80 23 23
      02 00 33 33
      00 00

//!!Warning (100): Default ID appears earlier in sprite.
   16 * 10   03 03 01 28 01 FF 01 00 01 00

   // Invisible rotor sprites for VTOL aircraft.
   17 * 4    01 03 01 04
   18 sprites/OSP_v0.png  8bpp  290 1224   17   11   -8   -5 normal chunked
   19 sprites/OSP_v0.png  8bpp  322 1224   25    9  -12   -4 normal
   20 sprites/OSP_v0.png  8bpp  354 1224   21   11  -10   -5 normal
   21 sprites/OSP_v0.png  8bpp  386 1224   17   11   -8   -5 normal
   22 * 9    02 03 04 01 01 00 00 00 00
//!!Error (85): This livery override action 3 does not follow a standard action 3.
   23 * 7    03 03 81 28 00 04 00

   24 * 19   04 03 7F 01 28 "It's a plane!" 00
   25 * 39   00 03 0F 01 28          // Model no
                      03 15          // Vehicle Life
                      04 18          // Model Life
                      06 0F          // Climate
                      08 FF          // New Gfx
                      09 00          // 02=plane, 00=helicopter
                      0A 00          // 00=small, 01=large
                      0B 16          // Cost
                      0C 26          // Speed (*8)
                      0D 7F          // Acceleration
                      0E 0F          // Running Cost (*~£337) (default *~£42)
                      0F 5F 00       // Passenger Capacity
                      11 23          // Mail Capacity
                      14 80          // Enable Sound callback
                      15 01          // Refit cost
                      1A 3F 55 0B 00 // Date of introduction

// END
Using what you've both said, this GRF now works the way I want it to. The vehicle has an invisible rotor and makes a funny jet engine sound on takeoff, and the purchase dialog even contains the custom text string I expect it to!

That said, there are still a couple of errors, I've left the results of nforenum in there to highlight where I'm doing something dumb. Whilst having a 'working' GRF is all well and good, it'd be nice to fix it proper, so I can get a better feel for how this stuff actually works, as well as making it less likely to break in future releases of (O)TTD(P).
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: Changing sounds using callbacks

Post by michael blunck »

AndyLandy wrote: [...] That said, there are still a couple of errors, I've left the results of nforenum in there to highlight where I'm doing something dumb.
I´m only seeing one (1) error w/r to that livery override. But again, see http://www.tt-forums.net/viewtopic.php? ... 0#p1067580. This should be OK.

regards
Michael
Image
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Changing sounds using callbacks

Post by PikkaBird »

Well, there is only one error and one warning that I can see (in case you didn't work it out, after renuming a long file you can simply search for "!!" to find the errors).

The error is caused by the override action 3 not being immediately after the normal action 3. As mb said, that is no longer required by OpenTTD or TTDPatch, but renum still calls it an error. It probably shouldn't.

The warning, like I said, is because you specify the default set-ID as a cargo specific set-ID in your action 3. This is unnecessary, but not wrong, so if you don't want to change it you can tell renum to ignore this in the way I specified earlier.
AndyLandy
Engineer
Engineer
Posts: 30
Joined: 10 Sep 2008 20:09

Re: Changing sounds using callbacks

Post by AndyLandy »

PikkaBird wrote:Well, there is only one error and one warning that I can see (in case you didn't work it out, after renuming a long file you can simply search for "!!" to find the errors).

The error is caused by the override action 3 not being immediately after the normal action 3. As mb said, that is no longer required by OpenTTD or TTDPatch, but NFO still calls it an error. It probably shouldn't.

The warning, like I said, is because you specify the default set-ID as a cargo specific set-ID in your action 3. This is unnecessary, but not wrong, so if you don't want to change it you can tell renum to ignore this in the way I specified earlier.
OK, excellent. Many thanks to you both! I've got the GRF working exactly the way I want it to, and I've fixed the warnings and errors too. I've moved the override Action3 directly after the regular Action3 because it does no harm to do so, and I've removed the superfluous cargo references. Now the file runs through nforenum without any report.

I'm also delighted to say that my trains GRF also runs through nforenum without any complaints either. I finally have two GRFs that compile cleanly and work the way I expect!

Probably means it's time to think about ships and road vehicles now! :lol:
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 14 guests