Advertisement
jille_Jr

OC: List components

Mar 29th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 KB | None | 0 0
  1. -- load component library
  2. local component = require "component"
  3. -- count = total connected components
  4. local count = 0
  5. -- to keep count of how many of each type
  6. local list = {}
  7.  
  8. -- list through all the components, store the values
  9. for path,type in component.list() do
  10.     count = count + 1
  11.     list[type] = (list[type] or 0) + 1
  12. end
  13.  
  14. -- loop through and print all components
  15. for type,count in pairs(list) do
  16.     if count == 1 then
  17.         -- singular
  18.         print(count.." "..type.." component")
  19.     else
  20.         -- plural
  21.         print(count.." "..type.." components")
  22.     end
  23. end
  24.  
  25. -- total components, plural thing
  26. if count == 1 then
  27.     -- singular
  28.     print(count.." component total")
  29. else
  30.     -- plural
  31.     print(count.." components total")
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement