Talk:GetSoundBPM: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "Is the warning correct? Warning says "trying to get the BPM from a sound directly after creation will not work" but the example does exactly that and it works.")
 
(Answer 1.)
 
Line 1: Line 1:
Is the warning correct? Warning says "trying to get the BPM from a sound directly after creation will not work" but the example does exactly that and it works.
Is the warning correct? Warning says "trying to get the BPM from a sound directly after creation will not work" but the example does exactly that and it works.<br>
{{MessageBox|
bordercolorhex = ADADAD |
title = Answer:|
message = Now it is correct.|
subtext = I updated the warning to be clearer.
The function works, but if you don't use a timer, the sound will play only after 1-3 seconds.<br>
Compare those examples:
<section name="Client" class="client" show="false">
This will play the song immediately. Then it will show the bpm after 1-3 seconds.
<syntaxhighlight lang="lua">
function bpm ()
    sound = playSound ("song.mp3")
    setTimer (function ()
        beats = getSoundBPM (sound)
        outputChatBox ("Long code version: " .. beats)
    end, 50, 1)
end
addCommandHandler ("bpm", bpm)
</syntaxhighlight>
</section>
<section name="Client" class="client" show="false">
This will play the song only when bpm is obtained (after 1-3 seconds).
<syntaxhighlight lang="lua">
function bpm ()
    sound = playSound ("song.mp3")
    beats = getSoundBPM (sound)
    outputChatBox ("Long code version: " .. beats)
end
addCommandHandler ("bpm", bpm)
</syntaxhighlight>
</section>
}}

Latest revision as of 20:48, 18 August 2021

Is the warning correct? Warning says "trying to get the BPM from a sound directly after creation will not work" but the example does exactly that and it works.

[[{{{image}}}|link=|]] Answer: Now it is correct.

I updated the warning to be clearer.

The function works, but if you don't use a timer, the sound will play only after 1-3 seconds.
Compare those examples:

Click to expand [+]
Client
Click to expand [+]
Client