Jump to content

BPM Counter


bradio10

Recommended Posts

Hi,

I am wanting to make a BPM counter with DX so that it will move up and down to the beat.

I'm not sure if this would be the way to do it but I have tried this way and it spams in the debug saying a userdata value

function test() 
    sound = playSound("playerpics/song.mp3") 
    counter = setTimer(function() getSoundBPM() end, 50, 0) 
    addEventHandler("onClientRender", root, bpmCounterDX) 
end 
addCommandHandler("testbpm", test) 
  
function bpmCounterDX() 
    dxDrawRectangle(1062, 484, 15, 112/1000*counter, tocolor(184, 1, 5, 255), true) 
    dxDrawRectangle(1099, 484, 15, 112/1000*counter, tocolor(156, 20, 161, 255), true) 
    dxDrawRectangle(1135, 484, 15, 112/1000*counter, tocolor(7, 161, 175, 255), true) 
    dxDrawRectangle(1173, 484, 15, 112/1000*counter, tocolor(172, 178, 5, 255), true) 
    dxDrawRectangle(1209, 484, 15, 112/1000*counter, tocolor(7, 182, 2, 255), true) 
end 

ERROR: musicplayer\client.lua:49: attempt to perform arithmetic on global 'counter' (a userdata value)

What is wrong and what is a userdata?

Thanks.

Link to comment

Userdata is an MTA element. If you bothered to read the wiki entry for setTimer, you would see it returns a timer element. Furthermore, you need to change line 3 to look like this.

counter = setTimer(getSoundBPM, 50, 0) 

I don't understand at all what you're attempting to do with this, but you're doing it wrong.

Link to comment
  • Moderators

I think he means this.

local counter = 1 
    function test() 
        sound = playSound("playerpics/song.mp3") 
        setTimer(function() counter = getSoundBPM() end, 50, 0)  
        addEventHandler("onClientRender", root, bpmCounterDX) 
    end 
    addCommandHandler("testbpm", test) 
      
    function bpmCounterDX() 
        dxDrawRectangle(1062, 484, 15, 112/1000*counter, tocolor(184, 1, 5, 255), true) 
        dxDrawRectangle(1099, 484, 15, 112/1000*counter, tocolor(156, 20, 161, 255), true) 
        dxDrawRectangle(1135, 484, 15, 112/1000*counter, tocolor(7, 161, 175, 255), true) 
        dxDrawRectangle(1173, 484, 15, 112/1000*counter, tocolor(172, 178, 5, 255), true) 
        dxDrawRectangle(1209, 484, 15, 112/1000*counter, tocolor(7, 182, 2, 255), true) 
    end 

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