{{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]] >> **ECBehaviorActorAIAction**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorActorAIAction ======
Behavior adding AI and Action support to actors.
Allows instance of BaseActorAction and BaseActorAI to be assigned to actor. During thinking first the AI then the Action is called.
Actions allow actors to perform a specific, well defined and enclosed action like interacting with an object. Actions are suitable to be used by player and computer controlled actors alike. This concept allows using the same actions for both player and computer controlled actors reducing coding effort, misbehavior and overall ensures that what a player can do a computer controlled actor can do and vice versa.
AIs allow computer controlled actors to act on their own. With player controlled actors the AI is skipped and the player is the AI. AI provides long running actor actions like guarding a zone with the possiblity to switch between different actions depending on how the actor wants to react to events. This separation makes it simple to design AI in coarse grain placing actual small grained actions into reusable action instances. This separation also allows actors to easily switch between player and computer controlled because both can reuse the same action instances.
====== Instance Counts ======
This behavior can be used only once on an element.
====== Element Class Properties ======
Element class properties have the prefix ''aiAction.''.
====== Events ======
Since this behavior provides no support to apply the chosen color listening is used. Behaviors knowing how to apply the color add a listener and are notified if the color changes. These events can be received:
====== Required Behaviors ======
This behavior requires no other behaviors.
====== Optional Behaviors ======
* [[behavior_colliderai|ECBehaviorColliderAI]]: Listen to events processing them with actions.
* [[behavior_conversationactor|ECBehaviorConversationActor]]: Add conversation commands and conditions.
* [[behavior_playercontrollable|ECBehaviorPlayerControllable]]: Listen to events processing them with actions.
====== Persistency ======
This behavior does support element class to be persistable (setPersistable). Saves active action and AI object.
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorActorAIAction.html,ECBehaviorActorAIAction~@#.
Since DragonScript Module Version ''1.0''
====== Use Cases ======
* Add action and AI support to actors.
====== Element Class Example ======
This example defines an element which action and AI support.
class MyElement extends BehaviorElementClass
public var ECBehaviorComponent component
public var ECBehaviorCollider collider
public var ECBehaviorColliderAI colliderAI
public var ECBehaviorConversationActor conversationActor
public var ECBehaviorPlayerControllable playerControllable
public var ECBehaviorActorAIAction aiAction
func new()
component = ECBehaviorComponent.new(this, null)
collider = ECBehaviorCollider.new(this, component)
colliderAI = ECBehaviorColliderAI.new(this, collider)
conversationActor = ECBehaviorConversationActor.new(this)
playerControllable = ECBehaviorPlayerControllable.new(this)
playerControllable.setConversationActor(conversationActor)
aiAction = ECBehaviorActorAIAction.new(this, colliderAI, conversationActor, pPlayerControllable)
end
end
====== Behavior Factory ======
Using element class supporting adding behaviors the behavior can be added like this:
value
====== Live Examples ======
* [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]