Howto:Play sound using Nasal script

From FlightGear wiki
Jump to navigation Jump to search

Here is a tutorial on how to play sound effects in FlightGear using Nasal and fgcommand.

Define the Audio Node in Nasal

To play a sound, FlightGear requires a property node structure containing the configuration of the audio sample:

var clickSound = props.Node.new({
    queue: "instant",                   # Use the 'instant' queue for zero-lag FX
    path: "Sounds",                     # The path containing click.wav
    file: "click.wav",                  # The filename
    volume: 1.0                         # Volume range from 0.0 to 1.0
});

Explanation of queue: "instant"

FlightGear uses audio queues to manage sound playback.

  • By default, sounds go to the chatter queue, which plays audio sequentially and is heavily used by ATC add-ons.
  • Specifying "instant" ensures your sound plays immediately without waiting in line, making it perfect for switch clicks, camera shutters, or warnings.

Play the sound

Use fgcommand("play-audio-sample", ...); to play it.

fgcommand("play-audio-sample", clickSound);

Related content