{{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]] >> **ECBehaviorConversation**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== 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 [[behavior_conversationactor|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:
* [[gamedev:deigde:editors:conversation|IGDE Conversation Editor]]
====== 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) intro.deconvo
===== 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) intro.desconvo
===== 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) player
===== 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) conversation
===== topic =====
Set topic.
* Full name: ''customColor.topic'' or ''customColor({id}).topic''
* Type: string
* Default Value: empty string
* Example (*.deeclass) intro
===== 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) false
===== trigger =====
Set trigger to start conversation.
* Full name: ''customColor.trigger'' or ''customColor({id}).trigger''
* Type: string
* Default Value: empty string
* Example (*.deeclass) @switchOnVent & @powerEnabled
====== Events ======
This behavior has no events.
====== Required Behaviors ======
* [[behavior_conversationactor|ECBehaviorConversationActor]]
====== Optional Behaviors ======
This behavior does not support optional behaviors.
====== Persistency ======
This behavior does support element class to be persistable (setPersistable).
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorConversation.html,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:
default
default
default
value
====== Live Examples ======
* [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]