Table of Contents

,

Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorAnnouncer

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 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.

type

Speaker type.

volume

Speaker volume.

range

Speaker range in meters. Speaker is inaudible beyond range.

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.

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.

shape

Speaker shape.

text

Announcement text.

position

Position to attach resource to collider.

orientation

Orientation to attach resource to collider in degrees.

bone

Bone to attach resource to. If empty string attach to collider.

trigger

Play announcement whenever trigger evaluates to true.

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.

ParameterValueDescription
textstringText to announce. If not set uses the last text.
text.translatestringText 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:

<action name='announcer.announce'>
  <parameter name='text.translated'>announcer.welcome</parameter>
</action>

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).

ParameterValueDescription
announcingtrue, falseAnnouncer 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:

<sequence>
  <action name='announcer.check'>
    <parameter name='announcing'>true</parameter>
  </action>
  <!-- actions here run only if announcer is announcing -->
</sequence>

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.

ParameterValueDescription
announcer.announcingtrue, falseAnnouncer is announcing

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='announcer.announcing'>true</parameter>
  <condition>announcer.check</condition>
</action>

State Machine Actions

Same as Behavior Tree Actions.

State Machine Conditions

Same as 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

Persistency

This behavior does not required element class to be persistable (setPersistable).

API Documentation

ECBehaviorAnnouncer.

Since DragonScript Module Version 1.0

Use Cases

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:

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorComponent'/>
  <behavior type='ECBehaviorCollider'/>
 
  <behavior type='ECBehaviorAnnouncer'>
    <!-- optional: set layer mask (default '2' meaning BaseGameApp.WorldLayerBit.audio).
                   list of bits to set. -->
    <string name='layerMask'>0 1 4</string>
 
    <!-- optional: use BaseGameApp trigger table. game can add more supported values -->
    <string name='triggerTable'>default</string>
 
    <!-- optional: identifier of ECBehaviorTriggered to synchronize with or empty
                   string to not synchronize. default is empty string. -->
    <string name='trigger.synchronize'>other</string>
 
    <!-- optional: use behavior tree with id instead of empty string -->
    <string name='behaviorTree'>second</string>
 
    <!-- optional: use state machine with id instead of empty string -->
    <string name='stateMachine'>second</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.text'>This is an announcement.</string>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorAnnouncer' id='second'/>
</elementClass>

Live Examples