Blitz3D+ Command Reference

WorldEntityID$ ( entity )

Parameters

entity - any live 3D entity

Description

Returns an entity's stable .world ID, or an empty string.

This is the reverse of FindWorldEntity: given an entity you are already holding - from a collision, a pick, or a parent walk - it tells you which authored entity it is. That makes it a solid key for save files and scripting ("the player touched door-keep-east"), because the ID comes from the .world source and never changes between runs.

Entities that were not created from a .world document - anything from CreateCube, LoadMesh, CopyEntity, or CreateWorldAsset - return an empty string, so it doubles as a cheap "is this a level entity?" test.

For the full story, see the Async World Loading guide.

Requires Extended mode.

See also: FindWorldEntity, WorldEntityMetadata, WorldAssetID, EntityWorld.

Example

; WorldEntityID Example
; ---------------------
; Requires Extended mode.

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

; Load a world whose author placed an invisible spawn marker
world=LoadWorldAsync("../../../samples/worlds/help-marker.world")
While Not WorldReady(world)
    If WorldLoadState(world)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(world)
    Cls
    Text 0,0,"Loading the marker world..."
    Flip
Wend

; Select the loaded world and give it a camera and a light
SetWorld world
camera=CreateCamera()
PositionEntity camera,0,1,-5
light=CreateLight()
RotateEntity light,45,45,0

; The authored marker entity, found by its stable ID
spawn=FindWorldEntity(world,"player-spawn")

; A locally created cone marks the spawn point visibly
player=CreateCone()
PositionEntity player,EntityX(spawn),EntityY(spawn),EntityZ(spawn)
EntityColor player,80,220,120
PointEntity camera,player

; WorldEntityID$ recovers the stable .world document ID of an entity;
; entities the document did not create report an empty string
spawn_id$=WorldEntityID(spawn)
player_id$=WorldEntityID(player)

While Not KeyDown(1)

    TurnEntity player,0,2,0

    ; 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,"Arrow keys: move camera   Esc: exit"
    Text 0,20,"WorldEntityID$(spawn) = '"+spawn_id+"'"
    Text 0,40,"WorldEntityID$(player) = '"+player_id+"' (the cone is not from the document)"

    Flip

Wend

FreeWorld world
End

Index