CountWorldEntityMetadata% ( entity )

Parameters

entity - an entity of a loaded world

Description

Returns how many metadata keys an entity was given in its .world file, such as the custom properties set in the World Editor's Custom properties section and its tags (the key tags).

Use it with WorldEntityMetadataKey$ to list the keys, and WorldEntityMetadata$ to read each value. Entities a program makes have none, so it returns 0 for them.

See also: WorldEntityMetadataKey, WorldEntityMetadata, GetWorldEntity.

Example

; CountWorldEntityMetadata Example
; --------------------------------

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

; A world whose coins carry tags and a score, set in the World Editor
world=LoadWorldAsync("../../../samples/worlds/help-coins.world")
While Not WorldReady(world)
    If WorldLoadState(world)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(world)
    Cls
    Text 0,0,"Loading the coins world..."
    Flip
Wend

SetWorld world
camera=CreateCamera()
PositionEntity camera,0,2,-5

chosen=0

While Not KeyDown(1)

    ; Tab chooses the next entity; it turns so you can see which
    If KeyHit(15) Then chosen=(chosen+1) Mod CountWorldEntities(world)
    entity=GetWorldEntity(world,chosen)
    TurnEntity entity,0,1,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   Tab: next entity   Esc: exit"
    ; How many metadata keys it has, then each key and its value
    count=CountWorldEntityMetadata(entity)
    Text 0,20,EntityName(entity)+": CountWorldEntityMetadata = "+count
    For index=0 To count-1
        key$=WorldEntityMetadataKey(entity,index)
        Text 20,40+index*16,key+" = "+WorldEntityMetadata(entity,key)
    Next

    Flip

Wend

FreeWorld world
End

Index