{{tag>dragonscript behavior}}
[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[dragengine:modules:dragonscript:abstractions|Abstraction Layers: How you want to build your Game]] >> [[dragengine:modules:dragonscript:behavior_elements|Behavior Elements]] >> **ECBehaviorAnnouncer**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorAnnouncer ======
Behavior element behavior adding announcer support.
Behavior uses an Announcer to play back announcer files. The speaker created by the Announcer instance is added to the game world.
If the [[behavior_collider|ECBehaviorCollider]] is present the announcer speaker is attached. The speaker is attached to the named bone if defined otherwise it is attached statically.
This behavior contains a property to set the announcement text. Other behaviors can change this text at runtime to make this alter the announcement. Changing the announcement text will stop playing back the current announcement.
====== Instance Counts ======
This behavior can be added multiple times to an element. Each instance creates one announcer speaker attached to the element collider which can be individually modified. To distinguish the announcers each instance has an identifier which can be used to retrieve a specific instance.
====== Element Class Properties ======
Element class properties have the prefix ''announcer.'' or ''announcer({id}).'' if id is not empty.
===== path =====
Path to announcer file to load.
* Full name: ''announcer.path'' or ''announcer({id}).path''
* Type: string
* Default Value: empty string
* Expected File Type: ''*.announcer.xml''
* Example (*.deeclass) speaker.announcer.xml
===== type =====
Speaker type.
* Full name: ''announcer.type'' or ''announcer({id}).type''
* Type: enumeration
* Allowed Values:
^Value^Description^
|''point''|Omnidirectional.|
|''directed''|Directed.|
* Default Value: ''point''
* Example (*.deeclass) directed
===== volume =====
Speaker volume.
* Full name: ''announcer.volume'' or ''announcer({id}).volume''
* Type: float
* Default Value: ''1''
* Restriction: At least ''0''
* Example (*.deeclass) 0.8
===== range =====
Speaker range in meters. Speaker is inaudible beyond range.
* Full name: ''announcer.range'' or ''announcer({id}).range''
* Type: float
* Default Value: ''30''
* Restriction: At least ''0''
* Example (*.deeclass) 20
===== rollOff =====
Roll off. Value ''1'' is realistic (normal) roll-off. Values larger than ''1'' reduce volume faster near the sound source. Values smaller than ''1'' reduce volume faster near the sound range.
* Full name: ''announcer.rollOff'' or ''announcer({id}).rollOff''
* Type: float
* Default Value: ''1''
* Restriction: At least ''0''
* Example (*.deeclass) 1.5
===== distanceOffset =====
Distance offset for attenuation calculation. For use by distance sounds. Offsets the true distance to the sound source for attenuation calculation to make the sound appear coming from far away. Requires increasing the volume to compensate for the distance increased attenuation.
* Full name: ''announcer.distanceOffset'' or ''announcer({id}).distanceOffset''
* Type: float
* Default Value: ''0''
* Restriction: At least ''0''
* Example (*.deeclass) 500
===== shape =====
Speaker shape.
* Full name: ''announcer.shape'' or ''announcer({id}).shape''
* Type: string (shape format). See "Shape List Encoding" in CodecPropertyString.
* Default Value: empty string
* Example (*.deeclass) box:position,0,0.5,0:extends,2,1,0.5
===== text =====
Announcement text.
* Full name: ''announcer.text'' or ''announcer({id}).text''
* Type: string
* Default Value: empty string
* Example (*.deeclass) This is an announcement.
===== position =====
Position to attach resource to collider.
* Full name: ''announcer.position'' or ''announcer({id}).position''
* Type: 3-component float vector
* Default Value: (0,0,0)
* Example (*.deeclass)
===== orientation =====
Orientation to attach resource to collider in degrees.
* Full name: ''announcer.orientation'' or ''announcer({id}).orientation''
* Type: 3-component float vector
* Default Value: (0,0,0)
* Example (*.deeclass)
===== bone =====
Bone to attach resource to. If empty string attach to collider.
* Full name: ''announcer.bone'' or ''announcer({id}).bone''
* Type: string
* Default Value: empty string
* Example (*.deeclass) attach
===== trigger =====
Play announcement whenever trigger evaluates to true.
* Full name: ''announcer.trigger'' or ''announcer({id}).trigger''
* Type: string
* Default Value: empty string
* Example (*.deeclass) @switchOnVent & @powerEnabled
====== Events ======
===== startAnnouncement =====
Start playing back announcement.
===== stopAnnouncement =====
Stop playing back announcement.
====== Behavior Tree Actions ======
This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace ''announcer'' with ''announcer(id)''.
===== announcer.announce =====
Start or stop announcing.
^Parameter^Value^Description^
|text|string|Text to announce. If not set uses the last text.|
|text.translate|string|Text to announce using TranslationManager to look up translation entry. If not set uses the last text.|
|stop| |If present stop announcement instead of starting it|
This is an example of using this action:
announcer.welcome
===== announcer.check =====
Check one or more announcer parameters. Action succeeds if all parameter value matches their respective announcer parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a announcer parameter matches (or not).
^Parameter^Value^Description^
|announcing|''true'', ''false''|Announcer is announcing|
|wait| |If present action returns BTResult.running instead of BTResult.failed to wait until the checks are all fulfilled|
This is an example of using this action:
true
====== Behavior Tree Conditions ======
This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace ''announcer'' with ''announcer(id)''.
===== announcer.check =====
Check one or more announcer parameters. Conditions returns true if all parameter value match their respective announcer parameter. This condition is typically used to run an action or sequence of actions as long as announcer conditions are true.
^Parameter^Value^Description^
|announcer.announcing|''true'', ''false''|Announcer is announcing|
This is an example of using this condition:
true
announcer.check
====== State Machine Actions ======
Same as [[#behavior_tree_actions|Behavior Tree Actions]].
====== State Machine Conditions ======
Same as [[#behavior_tree_conditions|Behavior Tree Conditions]].
====== State Machine Events ======
This behavior sends these state machine events. If behavior has non-empty identifier replace ''announcer'' with ''announcer(id)''.
===== announcer.start =====
Start playing back announcement.
===== announcer.stop =====
Stop playing back announcement.
====== Required Behaviors ======
This behavior requires no other behaviors.
====== Optional Behaviors ======
* [[behavior_collider|ECBehaviorCollider]]: Attach to collider.
* [[behavior_behaviortree|ECBehaviorBehaviorTree]]: Add actions and conditions for behavior trees to use.
* [[behavior_statemachine|ECBehaviorStateMachine]]: Add actions and conditions for state machine to use and events to send to the state machine.
====== Persistency ======
This behavior does not required element class to be persistable (setPersistable).
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorAnnouncer.html,ECBehaviorAnnouncer~@#.
Since DragonScript Module Version ''1.0''
====== Use Cases ======
* Play announcement through speaker composed of pre-recorded words.
====== Element Class Example ======
This example defines an element which supports playing announcements.
class MyElement extends BehaviorElementClass
public var ECBehaviorComponent component
public var ECBehaviorCollider collider
public var ECBehaviorAnnouncer announcer
func new()
component = ECBehaviorComponent.new(this, null)
collider = ECBehaviorCollider.new(this, component)
announcer = ECBehaviorAnnouncer.new(this, collider)
end
end
====== Behavior Factory ======
Using element class supporting adding behaviors the behavior can be added like this:
0 1 4
default
other
second
second
This is an announcement.
====== Live Examples ======
* [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]