Jump to content

[FIXED] Selection sound played on target death


zoot
 Share

Recommended Posts

This is a bug that I have experienced since Alpha 8, so I am surprised it has survived: when an attacking unit is selected and its target dies, its selection sound is played. I am not sure if it applies to all units in all cases, but I often hear a subtle "Ti esti?" every time something dies and its pretty annoying :P

Link to comment
Share on other sites

I've attached a save game for testing this issue. In the save game, a group of your units will be chasing a single enemy cavalry unit in the lower part of the map. To reproduce the bug, select the units chasing the cavalry unit and follow them until they kill it. When the cavalry unit dies, you will hear a "Ti esti?". If the units are not selected, the "Ti esti?" sound will not be played.

selectionsoundondeath.0adsave.zip

Link to comment
Share on other sites

  • 5 weeks later...

Okay, I've done a bit of sleuthing on this. I take the above back, the bug also applies to UnitAI kills. The offending call seems to be on selection.js:318. Apparently, what happens is that when a unit in the selection is promoted (as a consequence of killing its target), the selection gets rebuilt and the side-effect of this is that the selection sound is played.

The easy fix is to add a flag to the rebuildSelection() function to indicate whether the sound should be suppressed: https://github.com/zootzoot/0ad/compare/1713

Link to comment
Share on other sites

Okay, I've done a bit of sleuthing on this. I take the above back, the bug also applies to UnitAI kills. The offending call seems to be on selection.js:318. Apparently, what happens is that when a unit in the selection is promoted (as a consequence of killing its target), the selection gets rebuilt and the side-effect of this is that the selection sound is played.

The easy fix is to add a flag to the rebuildSelection() function to indicate whether the sound should be suppressed: https://github.com/z...ad/compare/1713

that is i like from this guy, go ahead Zoot.
Link to comment
Share on other sites

a minor note from my side: don’t use double negations in boolean expressions when you can avoid them.

instead of

 if (playsound !== false && owner == playerID || owner == 0 || g_DevSettings.controlAll)
_playSound(added[0]);

use

 if (playsound == true && owner == playerID || owner == 0 || g_DevSettings.controlAll)
_playSound(added[0]);

or even

 if (playsound && owner == playerID || owner == 0 || g_DevSettings.controlAll)
_playSound(added[0]);

that saves you 2 byte of disk space ( :wink2:) and is easier to understand

consider this example pseudo-c snippet(ask yourself which 'if' implements the desired behaviour; play the sound when sound is enabled)


if(disable_sound != false)
playsound(whatever);
if(enable_sound == true)
playsound(whatever);

in theory you could remove every occurance of "!== false" in the codebase…

EDIT: i just looked into the linked changeset, everything is ok, never said anything :ph34r:

Edited by luziferius
Link to comment
Share on other sites

a minor note from my side: don’t use double negations in boolean expressions when you can avoid them.

As leper implies, I was altering the prototype of an existing function. I couldn't have used "playsound == true" because existing code might be calling the function with no playsound argument, while still expecting the sound to be played. historic_bruno's ultimate formulation is less confusing, though.

Link to comment
Share on other sites

since that check isn’t copied 1:1 into the codebase i see my complain as [iNVALID], so only one last thing from my side

ok, I don’t know javascript. If there’s a semantic difference between var !== false and var == true for a boolean variable, your point is valid. isn’t there a warning when calling a function with too few parameters?

so there’s a difference between these 3 pseudo-js-functions?


function f1(bool_var)
{
if(bool_var !== false)
do_smth();
}
function f2(bool_var)
{
if(bool_var == true)
do_smth();
}
function f3(bool_var)
{
if(bool_var)
do_smth();
}

when calling those like this?


f1();
f2();
f3();

You know that the variable could be undefined or null right?

since it’s boolean algebra, you can’t have a semantic 'undefined' or 'null'; undefined is a random true or false and null normally is false and everything else is true

Edited by luziferius
Link to comment
Share on other sites

Ah I misread your earlier post slightly.

Since JavaScript is weakly typed you can have bool_var === undefined (though the check for !== false, works just as expected).

No, there isn't a warning issued as that can be defined/expected behaviour. Indeed === is just for type and value comparision, so it doesn't make a difference for booleans.

f1 does something, f2 and f3 don't. ('function f1' would make that example even correct js)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...