drk Posted January 30, 2012 Share Posted January 30, 2012 Hey all I'm trying to set a timer to execute 'playSound ( random )' when a sound stops. It starts a music. But in debugscript I see an error: 'setTimer' interval is below 50 on line 108. Line 108: setTimer(playSound,getSoundLength(currentSound)*1000,80,random); I don't see the problem, the interval is 1 and then I get the error, i've tried with 50,51 and 80 and I get the same error. Why ? Link to comment
DarkLink Posted January 30, 2012 Share Posted January 30, 2012 Português: Okay parece-me que tens ai alguns problemas, a função que passas para o timer é a playSound, depois o próximo argumento é o timeInterval do timer que multiplicas por 1000, a pensar que a função getSoundLength retorna o tempo em segundos? devolve em milliseconds, não precisas de multiplicar por 1000. depois tens o 80, ai é as vezes que queres que o timer corra a função, 80 vezes ? okay não há problema.. E depois passas nos argumentos, que serão os argumentos da função playSound passas um random ? tem de ser o arugmento da função playSound, que é uma String com o path da música como aqui indica : https://wiki.multitheftauto.com/wiki/PlaySound English: Okay it seems that u have some problems, the function passed to the timer is playSound, then the next argument is the timer TimeInterval multiply that by 1000, getSoundLength is not a function that returns the time in seconds so u dont need to multiply by 1000. It returns already on milliseconds, you do not need to multiply by 1000. Then you have the 80, this is the times you want to run the timer function, 80 times? okay no problem .. And the next arguments on timer are arguments for the function u call, in this case playSound need at least a argument with the sound path, I guess that its not a random? or maybe that random is a variable to a sound path? if you have any doubs u have here what I was talking about: https://wiki.multitheftauto.com/wiki/SetTimer -- look the arguments time interval is the second argument not the third https://wiki.multitheftauto.com/wiki/GetSoundLength -- returns on ms (milisseconds) https://wiki.multitheftauto.com/wiki/PlaySound -- sound path as string variable not a random ? PS: I know that this guy is portuguese so thats why I try to help on our native language, if he understands better I hope I could help you mate Good luck ! Link to comment
drk Posted January 30, 2012 Author Share Posted January 30, 2012 Aww shit School is fucking me :@ Link to comment
DarkLink Posted January 30, 2012 Share Posted January 30, 2012 Aww :~ School is me :@ what ? lol Link to comment
drk Posted January 30, 2012 Author Share Posted January 30, 2012 setTimer(playSound,getSoundLength(currentSound),80,random); I get the same error, Im doing something wrong? Link to comment
Evil-Cod3r Posted January 30, 2012 Share Posted January 30, 2012 Try This setTimer(playSound,getSoundLength(currentSound)*50,50,random); Link to comment
Castillo Posted January 30, 2012 Share Posted January 30, 2012 If I'm right, currentSound is not defined yet? because you're then using playSound (to play that sound?), maybe I'm wrong. Link to comment
drk Posted January 30, 2012 Author Share Posted January 30, 2012 currentSound is defined by playSound ( random, false ); . random is: local random = musicURL[math.random(#musicURL)] Link to comment
drk Posted January 30, 2012 Author Share Posted January 30, 2012 No one try to help ? Link to comment
JR10 Posted January 30, 2012 Share Posted January 30, 2012 If I get what you're saying right, you're using a variable returned by playSound with playSound, which won't work. playSound needs a string containing the path to the sound that will be played. So instead of currentSound, use random. Link to comment
drk Posted January 30, 2012 Author Share Posted January 30, 2012 Ive used 'random' but I get 'Cannot ... arithmetic on a bolean value' Edit: Ok, now I get 'Expected element at argument 2, got bolean' in the same line Link to comment
Scooby Posted January 31, 2012 Share Posted January 31, 2012 check this line: local random = musicURL[math.random(1,#musicURL)] also, u should try defining each variable if ur still having problems... so u can see which is causing the error. so rather than: setTimer(playSound,getSoundLength(currentSound)*1000,80,random); do something like: local rand = musicURL[math.random(1,#musicURL)] local length = getSoundLength(currentSound) outputDebugString("Length: " .. tostring(length) .. " - Random: " .. tostring(rand)) setTimer(playSound, length, 80, rand) if u output each variable like this, u will be able to find ur problem a lot easier since u will see which variable is wrong. also, u need to define currentSound or u could make this into function that loops once the current sound (random) is finished. Link to comment
arezu Posted January 31, 2012 Share Posted January 31, 2012 so i guess you are trying to play random sound after the current one stops.. use a more natural way then: local rand = musicURL[math.random(#musicURL)] local currentPlayingMusic = playSound(rand, false) addEventHandler("onClientElementDestroy", getRootElement(), function () if(source == currentPlayingMusic)then local rand = musicURL[math.random(#musicURL)] currentPlayingMusic = playSound(rand, false) end end) Link to comment
drk Posted January 31, 2012 Author Share Posted January 31, 2012 arezu, thanks. now I don't get any error but the song don't plays. the table: local musicURL = { 'http://199.167.195.178/wdga.mp3', 'http://199.167.195.178/pd.mp3', 'http://199.167.195.178/vlv.mp3', 'http://199.167.195.178/dk.mp3', 'http://199.167.195.178/tw.mp3', 'http://199.167.195.178/bh-aiew.mp3', 'http://199.167.195.178/wk-bay.mp3', 'http://199.167.195.178/sx-mnis.mp3', 'http://199.167.195.178/ib-sotg.mp3', 'http://199.167.195.178/mc-flm.mp3', 'http://199.167.195.178/ctm-gd.mp3', 'http://199.167.195.178/tv.mp3', 'http://199.167.195.178/wttc.mp3', 'http://199.167.195.178/iml.mp3', 'http://199.167.195.178/ctwykm.mp3', 'http://199.167.195.178/e-ksb9rx.mp3', 'http://199.167.195.178/Lights.mp3', 'http://199.167.195.178/nod.mp3', 'http://199.167.195.178/atb-yana.mp3' } the code: addEventHandler('onClientResourceStart',resourceRoot, function() local random = musicURL[math.random(1,#musicURL)] local currentSound = playSound(random,false); end); addEventHandler('onClientElementDestroy', root, function() if (source == currentSound) then local random = musicURL[math.random(1,#musicURL)] local currentSound = playSound(random,false); end; end); I've tried with local random = musicURL[math.random(#musicURL)] too but it don't play. Link to comment
Cadu12 Posted January 31, 2012 Share Posted January 31, 2012 local randomMusics = musicURL[math.random(#musicURL)] Try again. Link to comment
drk Posted January 31, 2012 Author Share Posted January 31, 2012 check this line: local random = musicURL[math.random(1,#musicURL)]also, u should try defining each variable if ur still having problems... so u can see which is causing the error. so rather than: setTimer(playSound,getSoundLength(currentSound)*1000,80,random); do something like: local rand = musicURL[math.random(1,#musicURL)] local length = getSoundLength(currentSound) outputDebugString("Length: " .. tostring(length) .. " - Random: " .. tostring(rand)) setTimer(playSound, length, 80, rand) if u output each variable like this, u will be able to find ur problem a lot easier since u will see which variable is wrong. also, u need to define currentSound or u could make this into function that loops once the current sound (random) is finished. It don't output anything and I don't get any error now. Only don't play songs. Link to comment
arezu Posted January 31, 2012 Share Posted January 31, 2012 arezu, thanks. now I don't get any error but the song don't plays. the table: local musicURL = { 'http://199.167.195.178/wdga.mp3', 'http://199.167.195.178/pd.mp3', 'http://199.167.195.178/vlv.mp3', 'http://199.167.195.178/dk.mp3', 'http://199.167.195.178/tw.mp3', 'http://199.167.195.178/bh-aiew.mp3', 'http://199.167.195.178/wk-bay.mp3', 'http://199.167.195.178/sx-mnis.mp3', 'http://199.167.195.178/ib-sotg.mp3', 'http://199.167.195.178/mc-flm.mp3', 'http://199.167.195.178/ctm-gd.mp3', 'http://199.167.195.178/tv.mp3', 'http://199.167.195.178/wttc.mp3', 'http://199.167.195.178/iml.mp3', 'http://199.167.195.178/ctwykm.mp3', 'http://199.167.195.178/e-ksb9rx.mp3', 'http://199.167.195.178/Lights.mp3', 'http://199.167.195.178/nod.mp3', 'http://199.167.195.178/atb-yana.mp3' } the code: local currentSound = nil; addEventHandler('onClientResourceStart',resourceRoot, function() local random = musicURL[math.random(1,#musicURL)]; currentSound = playSound(random,false); end); addEventHandler('onClientElementDestroy', root, function() if (source == currentSound) then local random = musicURL[math.random(1,#musicURL)]; currentSound = playSound(random,false); end end); I've tried with local random = musicURL[math.random(#musicURL)] too but it don't play. local currentSound and currentSound is not the same thing. If you use local inside a function, then it will only exist inside that function so do this.. (look up, i edit it) I just made currentSound a global variable instead Link to comment
drk Posted February 1, 2012 Author Share Posted February 1, 2012 Thaaanks veeeery much. It worked D: 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