Counting by names?


(John Andersson) #1

I know you can type how many entities are in the world with

FP.world.typeCount(“nameHere”)

but what about names?


(Zachary Lewis) #2

What names are you talking about?


(Jacob Albano) #3

I think he’s referring to the name property on entities.

Do you mean how can you find out how many entities have the same name? The answer is only ever one at most. If more than one entity has the same name, the most-recently added one will be found with getInstance().

There isn’t a way to get a list of all the names in current use, as far as I know.


(John Andersson) #4

Yes, I meant the name property.

I want to have an enemy which spawns offspring only if the amount of offspring currently in the world is less than 5 the enemies must have the “enemy” type to work in my game (long story)

any advice on a solution?


(Zachary Lewis) #5

After creating the offspring, you could store a reference to the offspring in some sort of collection (a Vector.<Offspring> or a linked list). Then, whenever you want to spawn a new offspring, check your list. If any offspring are dead or no longer exist, remove them from your list. If the final size of the list is less than five, proceed with spawning.