Jump to content

Problem with getSoundVolume


DjSt3rios

Recommended Posts

Hello... I have a weird problem. I made a button to increase the volume of a sound, and show on the screen the percentage of the sound volume... i made it volume*100, and it starts with 100%, i press - button to decrease volume and its going 90%. then i press again - to go 80% but it appears this: 79.9999923 and some other numbers, instead of 80%...

here is my code for increase/decrease volume:

function increasevolume() 
    setSoundVolume(song, getSoundVolume(song) + 0.10) 
    killTimer(hidetimer) 
    killTimer(hidetimer2) 
    showmessage = 1 
    hidetimer2 = setTimer(hidemessage, 5000, 1) 
end 
  
function decreasevolume() 
    setSoundVolume(song, getSoundVolume(song) - 0.10) 
    showmessage = 1 
    killTimer(hidetimer) 
    killTimer(hidetimer2) 
    hidetimer = setTimer(hidemessage, 5000, 1) 
end 
  
function hidemessage() 
    showmessage = 0 
end 
  
  

and onClientRender i use this code:

volume = getSoundVolume(song) 
            dxDrawText("Volume: " .. tonumber(volume*100) .. "%",  x1,y1-10,x2,y2, tocolor(255,0,0), 1.5, "pricedown","center","top", false,true,false) 

if someone has any idea, please tell me. thanks.

EDIT: I made a command with outputChatBox to show the exact number of getSoundVolume... so i found that that with setSoundVolume(song, vol + 0.1, it doesnt really increase it by exactly 0.1... maybe any idea to fix this?

Link to comment

use math.round

function math.round(number, decimals, method) 
    decimals = decimals or 0 
    local factor = 10 ^ decimals 
    if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor 
    else return tonumber(("%."..decimals.."f"):format(number)) end 
end 
  

Link to comment

Not really a difference when it comes to *ceil*'ing and *floor*'ing

> I had a problem which I only found a fix which was extremely dirty, if volume == 99% then volume = 100 end. This made sure it showed 100 when it was 99.xxxx

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