| world - world handle |
|
Returns how many things happened in a world during its last UpdateWorld. WorldEventName, WorldEventEntity and WorldEventOther say what each was, numbered from 0 to the count less one. The next UpdateWorld of the world starts a new list. Zone triggers send them: a zone made a trigger in the World Editor sends "entered" when an entity with its tag comes inside its shape, and "left" when it goes out, once each. Only the shape counts, not the zone's fade, and a hidden zone sends nothing. A trigger set to run only the first time sends its one entered event and nothing after. A trigger also runs its own actions, such as opening a door, so many triggers need no code at all; read the events for what a game adds, such as a score, a message or the next level. Built-in behaviours, given to objects in the World Editor's Behaviours section, send them too: "collected" when an object with a Collectible's tag touches it, and "arrived" when a Move between points reaches an end. The world sends "removed" whenever it takes an object away, for a Remove after time, a Collectible that removes, or a trigger's Remove. A removed object is hidden, and freed at the next UpdateWorld, so it can still be read until then, as for a coin's score. A program, and the behaviours of the world's own code, send events of their own with SendWorldEvent: they join the list at the next UpdateWorld. See also: WorldEventName, WorldEventEntity, WorldEventOther, TagEntity, ZoneWeight, StartBehaviour, SendWorldEvent. |
; CountWorldEvents Example
; ------------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
; A wall with a door: the porch in front of it is a zone that opens the
; door, lights a lantern and rings a bell when the player steps onto it.
; The camera is tagged player in the world file.
world=LoadWorldAsync("../../../samples/appearance/triggers.world")
While Not WorldReady(world)
If WorldLoadState(world)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(world)
UpdateAsyncLoads 2
Wend
SetWorld world
SetAudioWorld world
camera=FindWorldEntity(world,"camera")
said$="Walk forward onto the porch"
While Not KeyDown(1)
; Arrow keys walk the camera, which carries the listener
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,2,0
If KeyDown(205) Then TurnEntity camera,0,-2,0
; UpdateWorld tests the triggers; then each event says what happened
UpdateWorld
For i=0 To CountWorldEvents(world)-1
said=EntityName(WorldEventOther(world,i))+" "+WorldEventName(world,i)+" "+EntityName(WorldEventEntity(world,i))
Next
RenderWorld
Text 0,0,"Arrow keys: walk Esc: exit"
Text 0,20,said
Flip
Wend
End