|
| 27 Jul 2013 05:28 PM |
| I couldn't find any way/method so I ask how could I do so? |
|
|
| Report Abuse |
|
|
|
| 27 Jul 2013 05:32 PM |
Objects or parts?
function GetAmount(Parent, ClassName) local Count = 0 local function Scan(parent) for Index, Child in pairs(parent:GetChildren()) if Child:IsA(ClassName) or not ClassName then Count = Count + 1 end Scan(Child) end end Scan(Parent) end
print(GetAmount(Workspace)) --Everything print(GetAmount(Workspace, "BasePart")) --Just parts |
|
|
| Report Abuse |
|
|
|
| 27 Jul 2013 05:35 PM |
| That is relatively simple I should contemplate more before posting. |
|
|
| Report Abuse |
|
|
Java3D
|
  |
| Joined: 29 Jul 2012 |
| Total Posts: 1229 |
|
|
| 27 Jul 2013 05:51 PM |
Might be a little better than Cody's (no offence o:)
function CAll(a,c) local t = {} for n,o in pairs(a:GetChildren())do if(o:IsA(c))then table.insert(t,o)end for nu,ob in pairs(CAll(o,c))do table.insert(t,ob)end end return t end
local parts = CAll(Workspace,"BasePart") -- parts is now a table of all the parts in Workspace print(#parts) -- Using the pound symbol on a table returns it's length, so #parts is how many parts are in Workspace |
|
|
| Report Abuse |
|
|
|
| 27 Jul 2013 06:05 PM |
For objects:
#workspace:GetChildren()
For objects of a specific class, use the above users' scripts. |
|
|
| Report Abuse |
|
|
Java3D
|
  |
| Joined: 29 Jul 2012 |
| Total Posts: 1229 |
|
|
| 27 Jul 2013 06:08 PM |
| #CAll(Workspace,"Instance") gets the count of every instance (object) in Workspace :p |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 27 Jul 2013 06:12 PM |
ini = 1 recurse = function(n) ini = ini + #n:GetChildren() for _,v in pairs(n:GetChildren()) do recurse(v) end end recurse(Workspace) print(ini) |
|
|
| Report Abuse |
|
|
Java3D
|
  |
| Joined: 29 Jul 2012 |
| Total Posts: 1229 |
|
|
| 27 Jul 2013 06:22 PM |
| Your code is impractical, Absur. |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 27 Jul 2013 06:24 PM |
| My code is perfectly practical for his intentions, and is more efficient than yours. |
|
|
| Report Abuse |
|
|
Java3D
|
  |
| Joined: 29 Jul 2012 |
| Total Posts: 1229 |
|
|
| 27 Jul 2013 06:26 PM |
| Tell me how it's more efficient, and it's impractical because everytime you want to run it you would have to set ini back to 0. |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 27 Jul 2013 06:49 PM |
It's more efficient because I don't waste characters, lines and data on excess. I don't see how setting ini back to 0 is a problem. You can render that as an appositive if you need that, it's not much of a problem. |
|
|
| Report Abuse |
|
|
Java3D
|
  |
| Joined: 29 Jul 2012 |
| Total Posts: 1229 |
|
|
| 27 Jul 2013 07:18 PM |
| You could return the number instead of using a global variable. |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 27 Jul 2013 07:22 PM |
| Absurdism's code finishes faster and executes everything quicker. |
|
|
| Report Abuse |
|
|