of     1   

bluetheancient
#70438922Thursday, June 21, 2012 7:50 PM GMT

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.
robotmega
#70439025Thursday, June 21, 2012 7:52 PM GMT

local P = game.Workspace.Model a = P:getChildren() a.BrickColor = BrickColor.new("White")
zars15
#70439041Thursday, June 21, 2012 7:52 PM GMT

P = game.Workspace.Model for num, obj in pairs(P:GetChildren()) obj.BrickColor = BrickColor.new("White") wait() end
zars15
#70439076Thursday, June 21, 2012 7:52 PM GMT

@robot. Since when you can change color of table? Acctualy it would be so cute to have colorful arrays <3
bluetheancient
#70440042Thursday, June 21, 2012 8:07 PM GMT

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?
zars15
#70441033Thursday, June 21, 2012 8:23 PM GMT

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.
Spectrumw
#70441694Thursday, June 21, 2012 8:34 PM GMT

table.foreach(Workspace['Model']:GetChildren(), function(i, v) v.BrickColor = BrickColor.new('White') end) :D ?
zars15
#70441784Thursday, June 21, 2012 8:35 PM GMT

I laik doin classic way >:U
HilariousDwarf
#70441843Thursday, June 21, 2012 8:36 PM GMT

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)
zars15
#70442002Thursday, June 21, 2012 8:38 PM GMT

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
HilariousDwarf
#70442214Thursday, June 21, 2012 8:41 PM GMT

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.
zars15
#70442318Thursday, June 21, 2012 8:42 PM GMT

I learned to use for 1,blah do first too, but i find it bad for manipulating with children.
HilariousDwarf
#70442617Thursday, June 21, 2012 8:46 PM GMT

It does the same thing in this case :P
zars15
#70442898Thursday, June 21, 2012 8:50 PM GMT

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

    of     1