Jump to content

Stopping Sound doesn't stop?


Recommended Posts

I'm new to Lua and am trying to get a sound to stop. I looked at the Wiki and saw the stopSound.

Well the music does not stop and am getting an error:

bad argument at 'stopSound' expected sound at argument 1

  
addEventHandler ( "onClientClick", getRootElement(), results_click) 
    addEventHandler("onClientRender", getRootElement(), score_render) 
    setTimer(function() 
    results_d.enter = 'Press Enter To Hide' 
    results_d.res_dx.close[1] = (screenWidth - dxGetTextWidth ( results_d.enter, results_d.res_dx.size1,  "bankgothic" ))/2 
    bindKey ( "enter", "up", HideResultsT ) 
    end,4000,1) 
    stopSound ( cds ) 
end 
  

That's where it stops it at. But it's saying unknown sound.

It's clearly defined here:

  
addEventHandler("DestroyRoundTimer", getRootElement(), DestroyRoundTimer) 
G_hud = "0:0" 
local s_1_00 = false 
function getTimeFromMilisec(t) 
    local f = (t/1000)/60 
    m = math.modf(f) 
    s =  math.modf((f-m)*60) 
    G_hud = FormatTimer(m,s) 
        if s == 0 then 
            if m == 1 and s_1_00 == false then 
                s_1_00 = true 
                cds = playSound("sounds/alarm.ogg",false) 
                    setSoundVolume( cds,0.6) 
            end 
        end 
end 
  

am i missing something?

Link to comment

Replace line 9 in the first block from this:

stopSound ( cds ) 

to this:

if isElement(cds) then 
    stopSound ( cds ) 
end 

That will perform a check to see if the sound exist before trying to remove it. The reason is that you are trying to remove the sound before it's created due to the timer you are using, since I'm not sure what you are trying to do I guess this will be the best solution since it will verify that the sound exist before trying to remove it.

Link to comment
The reason is that you are trying to remove the sound before it's created due to the timer you are using

That's why it fixed it. Using a 50ms timer to stop the sound should have worked as well - but this is a better way of doing it. :)

I was in a hurry this afternoon and didn't see his message at the bottom.

I think i understand now.

Basically this is a sound file that plays at the 1 Minute Mark on the round countdown timer.

What i have noticed is that when you first connect, and the timer says 1 minute left, it plays and stops. But the next round, it will not play until you reconnect again.

Should i try setting cds to nil after the stopSound until it comes back to play again? No errors are in the log.

Link to comment

Ok so I'm not exactly sure as to how to get this 1 minute warning sound to play every round at the one minute remaining mark.

If you connect to the server, it plays at the right time, perfect. Then after that, it doesn't...until you reconnect.

Can anyone shed some light on this?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...