GetChildren (Method): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Oysi93
We don't want people iterating with numeric for, do we now...
>Camoy
more solid article
Line 1: Line 1:
<onlyinclude>{{Method
<onlyinclude>{{Method
|name                = GetChildren
|name                = GetChildren
|arguments            =
|returns              = [[Table]] ''children''
|returns              = [[Table]] ''children''
|description          = Returns a read-only table of this Object's children.
|description          = Returns a read-only table of the object's children.
|object              = Instance
|object              = Instance
}}</onlyinclude>
}}</onlyinclude>
{{clear floats}}
{{clear floats}}
*[[Loops#The_for_loop|For loop]] (Simple example)
{{Example|<pre>


{{Example|Using GetChildren with a [[Loops#The_for_loop|for loop]].<pre>
local children = game.Workspace:GetChildren()
local children = game.Workspace:GetChildren()
for c = 1, #children do
for i = 1, #children do
     print(children[c].Name)
     print(children[i].Name)
end
end
</pre>}}


</pre>}}
{{Example|Using GetChildren with a [[Generic for]], high recommended.<pre>
*[[Generic for]] (More efficient example)
for index, object in ipairs(game.Workspace:GetChildren()) do
*Highly recommended you use this one below.
     print("Index: ", index)
{{Example|<pre>
     print("Object:", object)
local children = game.Workspace:GetChildren()
for index, object in ipairs(children) do
     print("index: ",index)
     print("Object:",object)
end
end
</pre>}}
</pre>}}
[[Category:Methods]]

Revision as of 12:34, 18 January 2011

GetChildren( )
Returns Table children
Description: Returns a read-only table of the object's children.
Member of: Instance


Example
Using GetChildren with a for loop.
local children = game.Workspace:GetChildren()
for i = 1, #children do
    print(children[i].Name)
end


Example
Using GetChildren with a Generic for, high recommended.
for index, object in ipairs(game.Workspace:GetChildren()) do
    print("Index: ", index)
    print("Object:", object)
end