EntityClass$ ( entity )
Parameters
| entity - handle of the entity to identify |
Description
|
Returns the kind of an entity as a string, such as "Mesh", "Light" or "Camera". Every entity handle in Blitz3D+ is just an integer, so a variable holding one tells you nothing about what it points at. EntityClass answers the question. It is the tool you reach for whenever a handle arrives from somewhere you did not write - a level loaded from a file, a pick result, a walk through somebody else's entity tree - and you need to know whether it is safe to call a mesh command on it. The string is one of: Pivot, Light, Camera, Mirror, Listener, Decal, LineList, Sprite, Terrain, Plane, Mesh, MD2 or BSP. "Mesh" covers everything built from ordinary triangles, whether it came from CreateCube, LoadMesh or a glTF import; MD2 and BSP are the two model formats that keep their own renderer. Anything the engine does not otherwise recognise reports "Pivot", so treat "Pivot" as "no geometry here" rather than as proof that CreatePivot made it. The usual game pattern is guarding a call. Vertex, surface and mesh commands expect a mesh and will raise a runtime error on a light or a camera, so a loop over an imported scene reads much better as If EntityClass(child)="Mesh" Then ... than as a pile of hopeful assumptions. It is just as useful on the other side of a pick: after CameraPick you can branch on whether the player clicked scenery, a sprite or a terrain without keeping a lookup table of every handle you ever made. The result is worked out from the entity itself each time you ask, so it never goes stale - but it also never tells you anything about your own game logic. If you want to know that a mesh is an enemy rather than a crate, that is EntityName or EntityType, not EntityClass. See also: EntityName, EntityType, GetChild, CountChildren, PickedEntity, LoadGLTFScene. |
Example
; EntityClass Example ; ------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,2,-8 light=CreateLight() RotateEntity light,45,45,0 ; A little scene holding several different kinds of entity ground=CreatePlane() EntityPickMode ground,2 crate=CreateCube() PositionEntity crate,-2.5,1,0 EntityPickMode crate,2 ball=CreateSphere(16) PositionEntity ball,2.5,1,0 EntityPickMode ball,2 ; Not geometry at all - EntityClass is how you tell these from meshes marker=CreatePivot() PositionEntity marker,0,1,0 While Not KeyDown(1) TurnEntity crate,0,1,0 ; Shoot a pick ray through the mouse pointer, like a click-to-select cursor CameraPick camera,MouseX(),MouseY() ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Point the mouse at the crate, the ball or the floor Arrows: camera Esc: exit" hit=PickedEntity() If hit<>0 ; EntityClass names the kind of entity behind a handle you were handed Text 0,20,"EntityClass(PickedEntity()) = "+Chr$(34)+EntityClass(hit)+Chr$(34) Else Text 0,20,"Nothing under the pointer - EntityClass needs a real handle" EndIf Text 0,40,"camera -> "+EntityClass(camera)+" light -> "+EntityClass(light)+" marker -> "+EntityClass(marker) Text 0,60,"ground -> "+EntityClass(ground)+" crate -> "+EntityClass(crate)+" ball -> "+EntityClass(ball) Flip Wend End
Index