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