Jump to content

Interval is below 50


drk

Recommended Posts

Hey all xD 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 ? :S

Link to comment

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

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

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

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

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
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, 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

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...