Simple command for counting number of types?

Blitz3D Forums/Blitz3D Beginners Area/Simple command for counting number of types?

Farflame(Posted 2004) [#1]
Just getting to grips with types. Is there a simple command to tell me how many of a type I have 'alive', other than doing a quick loop and counting them myself?


poopla(Posted 2004) [#2]
No, but you can easily do it yourself.

For M.MyType = each MyType
Count = Count + 1
next


Farflame(Posted 2004) [#3]
k, thanks.


Perturbatio(Posted 2004) [#4]
A more optimized way of doing it would be to have a global type counter, and simply increment or decrement it by one each time you create or delete an instance of that type.


poopla(Posted 2004) [#5]
Global TypeCount

Function Create_MyType()
   M.MyType = new MyType
   TypeCount = TypeCount + 1
End Function 

Function Delete_MyType(M.MyType)
   Delete M
   TypeCount = TypeCount - 1
End Function 


I'd do what perturbatio said(like the example above).


Rob Farley(Posted 2004) [#6]
Yeah, but in most situations you cycle through all your types anyway so you can just stick a counter = counter + 1 within your type loop instead of having it as a seperate function.


poopla(Posted 2004) [#7]
Not like any of these are particularly "Right". :) Just a few options.


_PJ_(Posted 2004) [#8]
More here if it helps...
http://www.blitzbasic.com/Community/posts.php?topic=32915