|
entity - an entity with behaviours, from a loaded world or a copy of one id$ - the behaviour's ID, such as spin |
|
Returns True when UpdateWorld runs one of an entity's behaviours now: it is switched on, as BehaviourEnabled says, and the entity and each of its parents are shown and enabled. Behaviours of hidden or disabled entities wait. It returns False 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 calls a behaviour of the world's own code's Update only while this is True. See also: BehaviourEnabled, EnableBehaviour, CountWorldBehaviours. |
; CountWorldBehaviours Example
; ----------------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
; The coins world: coins that spin, bob and are collected, a gate, a sign and a guard
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")
hidden=False
While Not KeyDown(1)
; Space hides the first coin, and its behaviours wait while it is hidden
If KeyHit(57) Then
hidden=Not hidden
If hidden Then HideEntity coin Else ShowEntity coin
EndIf
UpdateWorld
RenderWorld
Text 0,0,"Space: hide or show Coin 1 Esc: exit"
; Each behaviour of each object, in the order they were made
y=20
For index=0 To CountWorldBehaviours(world)-1
owner=WorldBehaviourEntity(world,index)
state$="waits"
If BehaviourRunning(owner,WorldBehaviourID(world,index)) Then state$="runs"
Text 0,y,EntityName(owner)+": "+WorldBehaviourID(world,index)+" ("+WorldBehaviourKind(world,index)+") "+state$
y=y+16
Next
Flip
Wend
FreeWorld world
End