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 » Scripters
Home Search
 

Re: How to simultaneously set properties of the same type?

Previous Thread :: Next Thread 
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
12 Aug 2016 05:44 PM
I saw in a help request thread recently. My question has nothing to do with their initial question, but I was curious.
To set BodyColors, they did this:

local bodycolors = Instance.new("BodyColors", char)
bodycolors.HeadColor = BrickColor.new("Medium blue")
bodycolors.TorsoColor = BrickColor.new("Medium blue")
bodycolors.LeftArmColor = BrickColor.new("Medium blue")
bodycolors.LeftLegColor = BrickColor.new("Medium blue")
bodycolors.RightArmColor = BrickColor.new("Medium blue")
bodycolors.RightLegColor = BrickColor.new("Medium blue")

There has to be a cleaner way if I wanted to set these all to the same color.
Can I "iterate" through the properties, and if they accept a BrickColor value, change it?

Or, do I have to make a table of property names, then just iterate through the table of those properties and affect them by being like

properties = {
bodycolors.HeadColor,
bodycolors.TorsoColor,
bodycolors.LeftArmColor,
etc
}

for _,v in pairs(properties) do
v = BrickColor.new("Medium blue")
end

I don't this table idea. It's barely an improvement.
Any better way?


Report Abuse
Skellobit is not online. Skellobit
Joined: 13 Apr 2016
Total Posts: 12758
12 Aug 2016 05:51 PM
bodyParts = {"Head", "Torso", "RightArm", "LeftArm", "RightLeg", "LeftLeg"}

for _, v in pairs(bodyParts) do
bodyColors[v .. "Color"] = BrickColor.new("Medium blue")
end

Formerly ToxicDominator - add 17,509 posts
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
12 Aug 2016 05:53 PM
I'm trying to affect the Properties of a BodyColors object, not the BrickColors of the character's bodyparts.

This question extends to any object with more than one property of the same type.


Report Abuse
Skellobit is not online. Skellobit
Joined: 13 Apr 2016
Total Posts: 12758
12 Aug 2016 05:54 PM
did you even test it
you can access properties with brackets, and it concatenates the entry in the table to "Color" to fit a BodyColors property

Formerly ToxicDominator - add 17,509 posts
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
12 Aug 2016 05:58 PM
Didn't test, but skimmed.
Looks good, didn't know you could reference a property with brackets!


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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