Blinker. Posted July 26, 2014 Share Posted July 26, 2014 hello guys , i need a little help here with start / stop sound. well , i tried two methodes stopSound and setSoundVolume and both didn't work. here's my lua (client-side) function onGuiClick (button, state, absoluteX, absoluteY) if (source == startbutton) then local musicName = guiGridListGetItemText ( gridlist, guiGridListGetSelectedItem ( gridlist ), 1 ) if musicName == "Music 3" then local sound = playSound("music.mp3") setSoundVolume(sound,1) else if (source == stopbutton) then stopSound("music.mp3") --setSoundVolume(sound,0) end end end end the music starts when i click on the start button, but it doesn't stop when i click on the stop button. thanks in advance. Link to comment
Et-win Posted July 26, 2014 Share Posted July 26, 2014 stopSound(sound) Also DON'T make 'sound' local. Link to comment
Dealman Posted July 26, 2014 Share Posted July 26, 2014 So long as it's local to the function and he's stopping it within the function it should be fine to use local. Link to comment
Blinker. Posted July 26, 2014 Author Share Posted July 26, 2014 well , I tried that function onGuiClick (button, state, absoluteX, absoluteY) if (source == startbutton) then local musicName = guiGridListGetItemText ( gridlist, guiGridListGetSelectedItem ( gridlist ), 1 ) if musicName == "Music 3" then sound = playSound("music.mp3") setSoundVolume(sound,1) else if (source == stopbutton) then stopSound(sound) end end end end Still Can't Make the music Stop. Link to comment
Dealman Posted July 26, 2014 Share Posted July 26, 2014 Try to store it as a local variable at the top of the script instead, like this; local sound = nil; function exampleCode() if(true == false and false ~= true) then sound = playSound("File.mp3") end end Link to comment
Blinker. Posted July 26, 2014 Author Share Posted July 26, 2014 function exampleCode() if(true == false and false ~= true) then sound = playSound("File.mp3") end end function onGuiClick (button, state, absoluteX, absoluteY) if (source == startbutton) then local musicName = guiGridListGetItemText ( gridlist, guiGridListGetSelectedItem ( gridlist ), 1 ) if musicName == "Music 3" then setSoundVolume(sound,1) else if (source == stopbutton) then stopSound(sound) end end end end Should be like that ? I didn't understand it well Link to comment
Hex547 Posted July 26, 2014 Share Posted July 26, 2014 Hi there, Dealman referred you to me, I am his mentor, and I spotted your problem right away! Your problem lies in the fact your source can never be stopbutton because it's within the if statement whereby to get to that state it must be start button. In short/english: you need to put the "stopsound" else/if one level down by putting and end just before it. Hope this helps. Link to comment
Dealman Posted July 26, 2014 Share Posted July 26, 2014 Hi there, Dealman referred you to me, I am his mentor, and I spotted your problem right away!Your problem lies in the fact your source can never be stopbutton because it's within the if statement whereby to get to that state it must be start button. In short/english: you need to put the "stopsound" else/if one level down by putting and end just before it. Hope this helps. Link to comment
Blinker. Posted July 26, 2014 Author Share Posted July 26, 2014 it should be like that? function exampleCode() if(true == false and false ~= true) then sound = playSound("File.mp3") end end function onGuiClick (button, state, absoluteX, absoluteY) if (source == startbutton) then local musicName = guiGridListGetItemText ( gridlist, guiGridListGetSelectedItem ( gridlist ), 1 ) if musicName == "Music 3" then setSoundVolume(sound,1) end end if (source == stopbutton) then stopSound(sound) end end Link to comment
Hex547 Posted July 26, 2014 Share Posted July 26, 2014 Make sure the line local sound = nil is present at or near the top of the code, before any conditions, and also remove the function you got from Dealman, instead add sound = playSound("File.mp3") inside the first if statement somewhere, and don't forget to change the filename to your mp3. Link to comment
Blinker. Posted July 27, 2014 Author Share Posted July 27, 2014 Worked! , Many thanks mate Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now