|
| 06 Apr 2015 06:33 PM |
I'm learning about tables now and they gave an example script to change all the parts of a model to a different color and this is what they gave:
ch = game.Workspace.MyModel:GetChildren() --ch stands for children. ":GetChildren" can also be written as ":getChildren" for i = 1, #ch do if ch[i].className=="Part" then --"className" is a property of every Roblox object. "Part" means that it is a brick. ch[i].BrickColor=BrickColor.new("Black") --Every "Part" object has a "BrickColor" property. Trying to access the BrickColor property of a model would raise an error. end end
but my question just has to do with the second line; why are they using 'for i=1...'? |
|
|
| Report Abuse |
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 06 Apr 2015 06:38 PM |
They were using the for loop to go through the table, and the i later on as the index of each of the parts in the model.
However, there is a much simpler way to do all of this, examine the following code:
local model = game.Workspace.MyModel
for _, child in pairs(model:GetChildren()) do if child:IsA('BasePart') then child.BrickColor = BrickColor.new('Black') end end |
|
|
| Report Abuse |
|