..:D&G:.. Posted October 4, 2014 Posted October 4, 2014 Hello, I am trying to make something but ehm... I made a function which stops a song when a checkbox (songcheckbox) is checked, and play it when it's not. function checkboxSong() if ( getElementType(songcheckbox) == "gui-checkbox" ) then if (guiCheckBoxGetSelected(songcheckbox)) then stopSound(song) else playSound(song) end end end addEventHandler("onClientGUIClick", root, checkboxSong, false) The song line is in a function before this one, and it looks something like this: song = playSound("http://example.com/song.mp3") Now, I don't get why it isn't working Can someone please tell me what's wrong here? Thank you.
..:D&G:.. Posted October 4, 2014 Author Posted October 4, 2014 Nope, and I don't think that will work
Dealman Posted October 4, 2014 Posted October 4, 2014 function checkboxSong() if(source == songcheckbox) then if(guiCheckBoxGetSelected(songcheckbox)) then stopSound(song) else playSound(song) end end end addEventHandler("onClientGUIClick", root, checkboxSong)
..:D&G:.. Posted October 4, 2014 Author Posted October 4, 2014 function checkboxSong() if(source == songcheckbox) then if(guiCheckBoxGetSelected(songcheckbox)) then stopSound(song) else playSound(song) end end end addEventHandler("onClientGUIClick", root, checkboxSong) Thanks, that worked, but only for stopSound. After I unchecked the box, it doesn't play the sound again and I get the following error: Bad argument @ 'playSound' [Expected string at argument 1]
King12 Posted October 4, 2014 Posted October 4, 2014 function checkboxSong() if(source == songcheckbox) then if(guiCheckBoxGetSelected(songcheckbox)) then stopSound(song) elseif not (guiCheckBoxGetSelected(songcheckbox)) then playSound(song) end end end addEventHandler("onClientGUIClick", root, checkboxSong) but? song = playSound("http://example.com/song.mp3") how is that going to work if you already wrote playSound inside your function? it should be song = "http://example.com/song.mp3"
..:D&G:.. Posted October 4, 2014 Author Posted October 4, 2014 function checkboxSong() if(source == songcheckbox) then if(guiCheckBoxGetSelected(songcheckbox)) then stopSound(song) elseif not (guiCheckBoxGetSelected(songcheckbox)) then playSound(song) end end end addEventHandler("onClientGUIClick", root, checkboxSong) but? song = playSound("http://example.com/song.mp3") how is that going to work if you already wrote playSound inside your function? it should be song = "http://example.com/song.mp3" The line song = playSound("http://example.com/song.mp3") is in another function, I am only triggering that line from another function.
AfuSensi Posted October 5, 2014 Posted October 5, 2014 [quote name=..&G:..] function checkboxSong() if(source == songcheckbox) then if(guiCheckBoxGetSelected(songcheckbox)) then stopSound(song) elseif not (guiCheckBoxGetSelected(songcheckbox)) then playSound(song) end end end addEventHandler("onClientGUIClick", root, checkboxSong) but? song = playSound("http://example.com/song.mp3") how is that going to work if you already wrote playSound inside your function? it should be song = "http://example.com/song.mp3" The line song = playSound("http://example.com/song.mp3") is in another function, I am only triggering that line from another function. If you don't want the error "Bad argument @ 'playSound' [Expected string at argument 1]", then you should do it like he showed you. If you want to keep "song", define something like songURL = "http://songurl.com/song.mp3" and use it for the stopSound and playSound functions.
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