Cycle through all your entities without types or other structures.

Blitz3D Forums/Blitz3D Programming/Cycle through all your entities without types or other structures.

This requires the memory lib from www.leadwerks.com/code.

With this and the entity parameters commands, you don't even have to store your entities in any kind of type or array structure.

These commands will cycle through every entity that exists, even if you "forget" about it:
MoreEntities()
NextEntity()

Graphics3D 400,300,16,2

Include "EntityCycle.bb"

For n=1 To 5
	e=CreatePivot()
	NameEntity e,"Entity Number "+n
	Next

While MoreEntities()
	Print EntityName(NextEntity())
	Wend

Print ""

While MoreEntities()
	Print EntityName(NextEntity())
	Wend

WaitKey
End


EntityCycle.bb:
Const BLITZ_NEXT_ENTITY=4
Const BLITZ_LAST_ENTITY=8

Global FIRSTENTITY=CreatePivot()
Global CURRENTENTITYPOINTER=FIRSTENTITY

Function MoreEntities()
If PeekL(CURRENTENTITYPOINTER+BLITZ_NEXT_ENTITY)
	Return True
	Else
	CURRENTENTITYPOINTER=FIRSTENTITY
	EndIf
End Function

Function NextEntity()
entity=PeekL(CURRENTENTITYPOINTER+BLITZ_NEXT_ENTITY)
CURRENTENTITYPOINTER=entity
Return entity
End Function