|
entity - an entity with behaviours, from a loaded world or a copy of one id$ - the behaviour's ID, such as guard value - the number to keep with the behaviour |
|
Keeps a number with one of an entity's behaviours, which BehaviourData returns. A copy that CopyEntity makes starts again from 0. An ID the entity has no behaviour for is a runtime error. See also: BehaviourData, CountWorldBehaviours. |
; BehaviourData Example
; ---------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
; The coins world: each coin spins
world=LoadWorldAsync("../../../samples/behaviours/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=FindWorldEntityByName(world,"Camera")
PositionEntity camera,0,4,-6
RotateEntity camera,25,0,0
coin=FindWorldEntityByName(world,"Coin 1")
numbered=0
newest$=""
While Not KeyDown(1)
; Space copies the first coin: the copy's behaviours have no data yet
If KeyHit(57) Then
copy=CopyEntity(coin)
TranslateEntity copy,Rnd(-3,3),0,Rnd(-1,3)
EndIf
UpdateWorld
; Number each spin the first time it is seen, as a runner of behaviours does
For index=0 To CountWorldBehaviours(world)-1
owner=WorldBehaviourEntity(world,index)
id$=WorldBehaviourID(world,index)
If WorldBehaviourKind(world,index)="spin" And BehaviourData(owner,id$)=0 Then
numbered=numbered+1
SetBehaviourData owner,id$,numbered
newest$=EntityName(owner)+"'s spin is number "+numbered
EndIf
Next
RenderWorld
Text 0,0,"Space: copy Coin 1 Esc: exit"
Text 0,20,"Spins numbered: "+numbered
Text 0,40,newest$
Flip
Wend
FreeWorld world
End