CountChildren

This function gets the number of children an entity has in its immediate sub-hierarchy.

Syntax

Returns

Returns the number of children an entity has.

Example

--Create a window
window = Window:Create()
context = Context:Create(window)

world = World:Create()

local camera = Camera:Create()
camera:SetRotation(35,0,0)
camera:Move(0,0,-3)

local light = DirectionalLight:Create()
light:SetRotation(35,35,0)

--Load a model
entity = Model:Box()

local child = Model:Box(1,1,1,entity)
child:SetColor(1.0,0.0,0.0)
child:SetPosition(2,-2,0)

child = Model:Box(1,1,1,entity)
child:SetColor(0.0,1.0,0.0)
child:SetPosition(-2,-2,0)

while true do
if window:Closed() or window:KeyHit(Key.Escape) then return false end
Time:Update()
world:Update()
world:Render()

context:SetBlendMode(Blend.Alpha)
context:DrawText("The entity has "..entity:CountChildren().." children.",2,2)

context:Sync()
end