|
I am creating a script that involves changing the parts (about 60 or so) to a different color in a sequence. I need to shorten the script from about 400 lines to make it less laggy. Here is an example of my script:
local P = game.Workspace.Model
P.P1a.BrickColor = ("White")
P.P1b.BrickColor = ("White")
wait(.1)
P.P2a.BrickColor = ("White")
P.P2b.BrickColor = ("White")
P.P2c.BrickColor = ("White")
P.P2d.BrickColor = ("White")
P.P2e.BrickColor = ("White")
P.P2f.BrickColor = ("White")
Note: All of the parts will change to the same color.
|
|
robotmegaJoin Date: 2009-05-16 Post Count: 14599 |
local P = game.Workspace.Model
a = P:getChildren()
a.BrickColor = BrickColor.new("White") |
|
zars15Join Date: 2008-11-10 Post Count: 9999 |
P = game.Workspace.Model
for num, obj in pairs(P:GetChildren())
obj.BrickColor = BrickColor.new("White")
wait()
end |
|
zars15Join Date: 2008-11-10 Post Count: 9999 |
@robot. Since when you can change color of table? Acctualy it would be so cute to have colorful arrays <3 |
|
|
Can you put that bit of scripting in context so I can know exaclty where to put it? Also could you explain bit by bit what it means? |
|
zars15Join Date: 2008-11-10 Post Count: 9999 |
P = game.Workspace.Model --Defining P as model
for num, obj in pairs(P:GetChildren()) do --[[Loop, what will loop through all of P children]]
obj.BrickColor = BrickColor.new("White")--Sets current childs color to White
wait()--Waits for one frame
end--This is where loop ends/jumps to next part. |
|
SpectrumwJoin Date: 2009-08-04 Post Count: 13510 |
table.foreach(Workspace['Model']:GetChildren(), function(i, v) v.BrickColor = BrickColor.new('White') end)
:D ? |
|
zars15Join Date: 2008-11-10 Post Count: 9999 |
I laik doin classic way >:U |
|
|
A more easy-to-understand approach would be:
a - game.Workspace.Model:GetChildren() -- This gets the contents of "Model"
for i = 1, # a do -- this repeats the following script for each block inside
a[i].BrickColor = BrickColor.new("White") -- a[i] is the individual block, turning white.
end -- This ends the finite loop typed before (the for)
|
|
zars15Join Date: 2008-11-10 Post Count: 9999 |
for number = 1,#model:GetChildren() do
Is bad way of doing that... It's way more easier to use in pairs.
for number, object in pairs(model:GetChildren()) do |
|
|
I personally use for, as I find it easier myself and it was the way I learned it. I will eventually use pairs, but not now. |
|
zars15Join Date: 2008-11-10 Post Count: 9999 |
I learned to use for 1,blah do first too, but i find it bad for manipulating with children. |
|
|
It does the same thing in this case :P |
|
zars15Join Date: 2008-11-10 Post Count: 9999 |
It always does same thing. You can even do this:
c=game.Workspace:GetChildren()
for number, object in pairs(c) do
print(c[number].Name)
wait()
end
But why to do that if you can do this:
c=game.Workspace:GetChildren()
for number, object in pairs(c) do
print(object.Name)
wait()
end |
|