-- load component library
local component = require "component"
-- count = total connected components
local count = 0
-- to keep count of how many of each type
local list = {}
-- list through all the components, store the values
for path,type in component.list() do
count = count + 1
list[type] = (list[type] or 0) + 1
end
-- loop through and print all components
for type,count in pairs(list) do
if count == 1 then
-- singular
print(count.." "..type.." component")
else
-- plural
print(count.." "..type.." components")
end
end
-- total components, plural thing
if count == 1 then
-- singular
print(count.." component total")
else
-- plural
print(count.." components total")
end
Comments