|
entity - an entity with behaviours, from a loaded world or a copy of one id$ - the behaviour's ID, such as guard |
|
Returns the number a program keeps with one of an entity's behaviours, which SetBehaviourData sets. It is 0 to begin with, and 0 for the behaviours of a copy that CopyEntity makes, so a program can tell the behaviours it has seen from new ones. It is 0 too when the entity has no behaviour with that ID, or has been freed: the runner in the behaviours.bb that the World Editor writes keeps the Handle of each behaviour's object of code here, and so knows when its entity has gone. See also: SetBehaviourData, CountWorldBehaviours, BehaviourRunning. |
; 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