Hello! How can I play an audio file just for 1 second? I'm working on a burglar alarm system and I want to add a blip sound to it, and I want to play that audio file when I want to turn off the alarm. I know I have to write playSFX("AUDIO") but idk how to change an end time for it, if I write it, it will play for ever as a loop. Please give me a code, I'm new at lua scripting. Thanks in advance!
Something like this should work (I haven't tested the whole code out yet but I think it will work). And call "playSound" to play the sound effect for 1 second: Code: local M = {} local sfx_source = nil --1 second of playing sound local play_time = 1 local timer = -1 local function init(jbeamData) --Replace with your sound file local sound_file = "art/sound/fireloop.ogg" --Initialize sound sfx_source = obj:createSFXSource(sound_file, "AudioDefaultLoop3D", "", 1) end local function playSound() obj:setVolume(sfx_source, 1) obj:playSFX(sfx_source) timer = 0 end local function updateGFX(dt) --Stop playing audio if 1 second elapsed if timer > play_time then obj:setVolume(sfx_source, 0) obj:stopSFX(sfx_source) --Stops timer timer = -1 end --Only run timer if playing audio currently if timer ~= -1 then timer = timer + dt end end M.init = init M.playSound = playSound M.updateGFX = updateGFX return M