..: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. MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
darhal Posted October 4, 2014 Posted October 4, 2014 if getElementType(source) then any errors ? #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
..:D&G:.. Posted October 4, 2014 Author Posted October 4, 2014 Nope, and I don't think that will work MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
darhal Posted October 4, 2014 Posted October 4, 2014 Show us where song defined #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
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) If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.
darhal Posted October 4, 2014 Posted October 4, 2014 Song should be url or file see wiki #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
..: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] MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
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. MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
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