Simple command for counting number of types?

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

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?

No, but you can easily do it yourself.

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

k, thanks.

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.

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).

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.

Not like any of these are particularly "Right". :) Just a few options.

More here if it helps...
http://www.blitzbasic.com/Community/posts.php?topic=32915