generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Hey..

Previous Thread :: Next Thread 
garretcat is not online. garretcat
Joined: 04 Feb 2009
Total Posts: 757
07 Nov 2011 03:51 PM
Is there a .Changed event for The Volume of a sound?

I thought there was, But it's giving me a hard time. Giving me this error:

attempt to index field 'Volume' (a number value)
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 03:53 PM
`Events` do not run on properties, they are used on objects.

    sound.Changed:connect(function(prop)
        if prop == "Volume" then
            --code
        end
    end)
Report Abuse
garretcat is not online. garretcat
Joined: 04 Feb 2009
Total Posts: 757
07 Nov 2011 04:03 PM
Then tell me what is wrong with this >.>

script.Parent.Parent.music.Changed:connect(function(prop)
if prop == "Volume" then
if prop.Value == 1 then
x = Max
elseif prop.Value == 0 then
x = Min
else
x = prop.Value
script.Parent.Text = ("Volume: "..x.." ")
end
end
end)

error I get is:

attempt to concatenate global 'x' (a nil value)
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:10 PM
prop is a string that is the property that changed. You still have to use sound.Volume.
Report Abuse
garretcat is not online. garretcat
Joined: 04 Feb 2009
Total Posts: 757
07 Nov 2011 04:15 PM
Sigh. That worked but It's giving me strange decimals like 0.699399999 Instead of 0.7. Is there a EASY way to round up, That dosent require repeditive If Statements?
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:18 PM
Yes, there are. Multiple ways, mind you. The easiest way is:

    function round(n)
        return math.floor(n + 0.5)
    end

So, now you can do:

    round(5.7)

And it will return 6.
Report Abuse
PompeyTheGreat is not online. PompeyTheGreat
Joined: 10 Apr 2011
Total Posts: 5615
07 Nov 2011 04:25 PM
math.ceil rounds up, math.floor rounds down.

I think...
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:28 PM
@pompey - Yes, but you didn't explain how to actually round, which I did. :P
Report Abuse
garretcat is not online. garretcat
Joined: 04 Feb 2009
Total Posts: 757
07 Nov 2011 04:28 PM
I almost feel pathetic :c

function round(n)
num = math.floor(n + 0.5)
end

script.Parent.Parent.music.Changed:connect(function(prop)
if prop == "Volume" then
if script.Parent.Parent.music.Volume == 1 then
script.Parent.Text = ("Volume: Max")
elseif script.Parent.Parent.music.Volume == 0 then
script.Parent.Text = ("Volume: Min")
elseif script.Parent.Parent.music.Volume == not 1 and not 0 then
round(script.Parent.Parent.music.Volume)
x = num
script.Parent.Text = ("Volume: "..x.." ")
end
end
end)
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:31 PM
> round(script.Parent.Parent.music.Volume)
x = num

Change those two lines to:

    local x = round(script.Parent.Parent.music.Volume)
Report Abuse
PompeyTheGreat is not online. PompeyTheGreat
Joined: 10 Apr 2011
Total Posts: 5615
07 Nov 2011 04:31 PM
Why would you add .5 to it?
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:32 PM
@Pompey - Do the math and/or try it out yourself. I don't feel like explaining. :P
Report Abuse
garretcat is not online. garretcat
Joined: 04 Feb 2009
Total Posts: 757
07 Nov 2011 04:41 PM
I changed it a little, Im not getting any errors, but the THe Mute/Max Only work.

function round(n)
num = math.floor(n + 0.5)
end

script.Parent.Parent.Parent.Parent.Parent.music.Changed:connect(function(prop)
if prop == "Volume" then
if script.Parent.Parent.Parent.Parent.Parent.music.Volume == 1 then
script.Parent.Text = ("Volume: Max")
elseif script.Parent.Parent.Parent.Parent.Parent.music.Volume == 0 then
script.Parent.Text = ("Volume: Mute")
elseif script.Parent.Parent.Parent.Parent.Parent.music.Volume == not 1 and not 0 then
local x = round(script.Parent.Parent.Parent.Parent.Parent.music.Volume)
script.Parent.Text = ("Volume: "..x.." ")
end
end
end)
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:43 PM
Change:

    elseif script.Parent.Parent.Parent.Parent.Parent.music.Volume == not 1 and not 0 then

to:

    elseif script.Parent.Parent.Parent.Parent.Parent.music.Volume ~= 1 and script.Parent.Parent.Parent.Parent.Parent.music.Volume ~= 0 then
Report Abuse
garretcat is not online. garretcat
Joined: 04 Feb 2009
Total Posts: 757
07 Nov 2011 04:45 PM
Made said changes.

error.

attempt to concatenate local 'x' (a nil value)
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:46 PM
...You edited the round function.

Change:

    num = math.floor(n + 0.5)

to:

    return math.floor(n + 0.5)
Report Abuse
garretcat is not online. garretcat
Joined: 04 Feb 2009
Total Posts: 757
07 Nov 2011 04:49 PM
That worked, But one problem I did not notice before, and I should have.

The rounding rounds to whole numbers. I need a Decimal. One place decimal

0.1,0.2,0.3,so on
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:51 PM
Hmm... Not sure if this would work, but try changing 0.5 to 0.05.
Report Abuse
garretcat is not online. garretcat
Joined: 04 Feb 2009
Total Posts: 757
07 Nov 2011 04:52 PM
Nope, Just prints 0.

(I made it print the value so It's easy to check)
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 04:54 PM
Oh, math.floor rounds it to a whole nunber... Hold on, I'll go check something
Report Abuse
garretcat is not online. garretcat
Joined: 04 Feb 2009
Total Posts: 757
07 Nov 2011 06:45 PM
:o
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
07 Nov 2011 07:28 PM
Alright, did some research. Replace the round function with this:

    function round(n, i)
        local mult = 10^(i or 0)
        return math.floor(n * mult + 0.5) / mult
    end

Now, when you use this, the second argument should be 1 if you want it to round to the tenths place.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image