WorldEntityMetadataKey$ ( entity,index )

Parameters

entity - an entity of a loaded world

index - from 0 to CountWorldEntityMetadata(entity) less one

Description

Returns the name of one of an entity's metadata keys, in alphabetical order. Pass it to WorldEntityMetadata$ to read the value.

Keys include the custom properties set in the World Editor, the key tags that holds its tags, and keys starting b3d. that the engine and editor keep for themselves.

An index outside the list is a runtime error.

See also: CountWorldEntityMetadata, WorldEntityMetadata, EntityHasTag.

Example

; WorldEntityMetadataKey Example
; ------------------------------

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

; A world whose coins carry tags, a score and a colour
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

coin_number=0

While Not KeyDown(1)

    ; Tab chooses the next coin, which turns
    If KeyHit(15) Then coin_number=(coin_number+1) Mod CountTaggedEntities(world,"coin")
    coin=GetTaggedEntity(world,"coin",coin_number)
    TurnEntity coin,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   Tab: next coin   Esc: exit"
    ; Every key the coin was given, by its number
    Text 0,20,EntityName(coin)+" has these keys:"
    For index=0 To CountWorldEntityMetadata(coin)-1
        key$=WorldEntityMetadataKey(coin,index)
        Text 20,40+index*16,"WorldEntityMetadataKey(coin,"+index+") = "+key
    Next

    Flip

Wend

FreeWorld world
End

Index