|
entity - any entity tag$ - a word to find it by, such as player or coin |
|
Gives an entity a tag, a word that a program and zone triggers find it by. An entity can have any number of tags; giving it one it has already does nothing. Objects in a world file get theirs from the World Editor: the Tags field in the Object section, saved as the object's "tags" metadata. TagEntity tags anything, including entities a program makes, while it runs: tag a ball player, and the world's zone triggers that wait for the player notice it. Copies made with CopyEntity keep their tags, and an entity that is freed is no longer found by them. A tag is a word of 1 to 64 letters, digits, _ and -, and matches whatever its case: Player and player are the same tag. Anything else is a runtime error. See also: UntagEntity, EntityHasTag, CountTaggedEntities, GetTaggedEntity, CountWorldEvents. |
; TagEntity 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")
; Take the camera's tag away, so the porch does not notice it, and give it
; to a ball that this program makes and rolls onto the porch instead
UntagEntity camera,"player"
ball=CreateSphere()
ScaleEntity ball,0.3,0.3,0.3
EntityColor ball,255,80,60
PositionEntity ball,0,0.3,-4
TagEntity ball,"player"
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
; The ball rolls slowly towards the door; the porch opens it
If EntityZ(ball)<3 Then MoveEntity ball,0,0,0.02
UpdateWorld
RenderWorld
Text 0,0,"The red ball is the player now: watch the door Esc: exit"
Flip
Wend
End