From ZDoom Wiki
Jump to navigation Jump to search

clearscope void A_StartSoundIfNotSame (sound whattoplay, sound checkagainst [, int slot [, int flags [, double volume [, double attenuation [, double pitch [, double startTime]]]]]])


Plays the specified sound only if it is different from the one to check against.

The two sounds are considered different if they have different names. For aliases, the function checks the name of the sound which is referenced by the alias in order to make a decision. A random sound's assigned set of sounds is of no consequence, as the function only checks the sound's name.


  • whattoplay: the desired sound to play, as defined in SNDINFO.
  • checkagainst: the sound to check against, as defined in SNDINFO.
  • slot: the sound slot used for the sound. Unlike A_PlaySound, the slot is not limited to predefined slots and can be any number other than 0 (which instructs GZDoom to use another slot) and -1. The predefined slots are:
  • CHAN_AUTO (0) — Use the first channel that is not already playing something.
  • CHAN_VOICE (2)
  • CHAN_ITEM (3)
  • CHAN_BODY (4) — Default.
  • CHAN_5 (5)
  • CHAN_6 (6)
  • CHAN_7 (7)
  • flags: adjusts how the sound is played. Multiple flags can be combined by using the bitwise OR (|) operator:
  • CHANF_DEFAULT — No flags. Default.
  • CHANF_LISTENERZ — Played from the listener's Z-height. (Verification needed)
  • CHANF_MAYBE_LOCAL — Is subject to compat_silentpickup and will not play if the sound is made by an actor other than the local player's camera when the compatibility flag is enabled.
  • CHANF_UI — Is not preserved in savegames.
  • CHANF_NOPAUSE — Does not pause in menus.
  • CHANF_LOOP — Loops the sound.
  • CHANF_OVERLAP — Does not stop any sounds in the channel and instead plays over them.
  • CHANF_LOCAL — Only plays locally for the calling actor.
  • CHANF_NOSTOP — If the channel is occupied, do not play the sound.
  • CHANF_LOOPING — Combines CHANF_LOOP and CHANF_NOSTOP. It is equivalent to the looping parameter of A_PlaySound.
  • volume: the volume of the sound, which ranges from 0 to 1.0. Default 1.0.
  • attenuation: this is a positive value that specifies how quickly the sound fades with distance from its source. The higher the value the quicker it fades out. The numbers are fairly low. A dramatic drop off of volume is noticeable with an attenuation value of just 3 or 4. With a value of 20, for instance, the player needs to be within around 64 units of the sound source to hear it clearly. The following predefined constants exist:
  • ATTN_NONE — Plays the sound globally at the specified volume, disregarding distance.
  • ATTN_NORM — Uses the close_dist and clipping_dist fields defined in the sound definition. Default.
  • ATTN_IDLE — Uses Doom's normal default sound attenuation behavior.
  • ATTN_STATIC — Fades quickly (inaudible from 512 units).
  • pitch: the sound pitch to play the sound with. Default is 0, which means the engine uses whatever pitch shift (range) that is defined in SNDINFO, if any. For non-zero values anything lower than 1.0 will slow down the sound, while higher values speed it up.
  • startTime: sets how much of the sound to skip when starting. The value can be anywhere between 0 and 1.0, translating to 0% to 100%. Default is 0.


Nuvolachalk.png Note: This article lists no examples. If you make use of this feature in your own project(s) or know of any basic examples that could be shared, please add them. This will make it easier to understand for future authors seeking assistance. Your contributions are greatly appreciated.

See also