User Tools

Site Tools


dragengine:modules:dragonscript:behavior_conversation

ECBehaviorConversation

Behavior element behavior adding conversation support.

Loads a conversation resource file and allows to start a conversation using a user defined topic. Conversations are loaded once so multiple behaviors can load the same conversation file without doing the actual loading multiple times.

By default the conversation is started without adding any actors.

If the addPlayer stub property is not empty string the BaseGameApp.getPlayerControlledActor() actor is added to the conversation as first actor using the property value as its alias id. If the actor does not have a BaseActorConversation assigned an exception is thrown. The default element class property sets AddPlayer to player.

If ECBehaviorConversationActor is present and has a conversation actor it is added as second actor to the conversation using the property valus as id. Additional actors can be added using conversation actions.

If the directCamera stub property is true the conversation does direct the camera using ConversationCameraDirector instance. The default element class property sets DirectCamera to true. Set this property to false to keep the camera unchanged which is required to do first person camera animations.

Starting the conversation can be done by calling startConversation(). This can be done by other behaviors or a subclass. Care has to be taken when starting conversation if another conversation is running. Actors are not allowed to be involved in more than one conversation but any number of conversation can be running at the same time as long as this rule is fulfilled.

To protect against this situation the method canStartConversation() is provided. It checks if the player and this behavior element have a ConversationActor and are both not involved in a conversation (given they are used for the conversation).

A typical use pattern is to start a conversation with a suitable element if the player uses said element. The code example below shows how this can be done in a simple way.

// this method is assumed to be called by the player implementation when he uses
// an element. this method is usually part of an ElementVisitor subclass
func void visitBehaviorElement(BehaviorElement element)
  var ECBehaviorConversation.Instance instance = ECBehaviorConversation.getInstanceIn(element)
  if instance != null and instance.canStartConversation()
    instance.startConversation()
  end
end

It checks if a behavior element has the ECBehaviorConversation behavior present. If this is the case it checks if the conversation can be started and starts it.

Another way to start a conversation is using the triggerConversation. If this trigger expression is not empty it will be used to start the conversation if the trigger expression evaluates to true. The method canStartConversation() is used to not check if the conversation is possible. If the check fails an exception is thrown to not silently not start a conversation.

This method is typically used to trigger conversation if the player enters a TriggerTouch or he finished a sequence of actions ending in firing a trigger.

See also:

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix conversation. .

path

Set path to conversation to use.

  • Full name: customColor.path or customColor({id}).path
  • Type: string
  • Default Value: empty string
  • Expected File Pattern: *.deconvo
  • Example (*.deeclass)
    <string name='customColor.path'>intro.deconvo</string>

pathSimple

Set path to simple conversation to use.

  • Full name: customColor.pathSimple or customColor({id}).pathSimple
  • Type: string
  • Default Value: empty string
  • Expected File Pattern: *.desconvo
  • Example (*.deeclass)
    <string name='customColor.pathSimple'>intro.desconvo</string>

addPlayer

Set add player alias. If not empty adds player to conversation using this alias.

  • Full name: customColor.addPlayer or customColor({id}).addPlayer
  • Type: string
  • Default Value: player
  • Example (*.deeclass)
    <string name='customColor.addPlayer'>player</string>

topicGroup

Set topic group. If topic group is empty string simple conversation is used.

  • Full name: customColor.topicGroup or customColor({id}).topicGroup
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='customColor.topicGroup'>conversation</string>

topic

Set topic.

  • Full name: customColor.topic or customColor({id}).topic
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='customColor.topic'>intro</string>

directCamera

Set activate direct camera. If true the conversation camera is set as active camera director upon starting the conversation.

  • Full name: customColor.directCamera or customColor({id}).directCamera
  • Type: boolean
  • Default Value: true
  • Example (*.deeclass)
    <boolean name='customColor.directCamera'>false</boolean>

trigger

Set trigger to start conversation.

  • Full name: customColor.trigger or customColor({id}).trigger
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='customColor.trigger'>@switchOnVent & @powerEnabled</string>

Events

This behavior has no events.

Required Behaviors

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

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

API Documentation

ECBehaviorConversation.

Since DragonScript Module Version 1.0

Use Cases

  • Start conversation if trigger evaluates to true.

Element Class Example

This example defines an element which can start a conversation.

class MyElement extends BehaviorElementClass
  public var ECBehaviorConversationActor conversationActor
  public var ECBehaviorConversation conversation
  func new()
    conversationActor = ECBehaviorConversationActor.new(this)
    conversation = ECBehaviorConversation.new(this, conversationActor)
  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='ECBehaviorConversationActor'/>
 
  <behavior type='ECBehaviorConversation'>
    <!-- optional: use BaseGameApp trigger table. game can add more supported values.
                   default is 'default' -->
    <string name='triggerTable'>default</string>
 
    <!-- optional: use BaseGameApp player controllable actor.
                   game can add more supported values. default is 'default' -->
    <string name='playerControllableActor'>default</string>
 
    <!-- optional: use BaseGameApp simple conversation converter.
                   game can add more supported values. default is 'default' -->
    <string name='simpleConversationConverter'>default</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.name'>value</string>
  </behavior>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_conversation.txt · Last modified: 2025/03/12 19:41 by dragonlord