This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| dragengine:modules:dragonscript:behavior_flags [2026/10/12 11:59] – removed - external edit (Unknown date) 127.0.0.1 | dragengine:modules:dragonscript:behavior_flags [2026/10/12 12:04] (current) – dragonlord | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | {{tag> | ||
| + | <WRAP youarehere> | ||
| + | [[: | ||
| + | </ | ||
| + | |||
| + | * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] | ||
| + | * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] | ||
| + | |||
| + | ====== ECBehaviorFlags ====== | ||
| + | |||
| + | Behavior element behavior adding flags support to behavior trees and state machines. | ||
| + | |||
| + | Adds actions, conditions and events allowing behavior trees and state machines to set, clear and check named flags. Flags are stored per element instance. Flags that are not set are considered cleared. Flags are persisted together with the element. | ||
| + | |||
| + | ====== Instance Counts ====== | ||
| + | |||
| + | This behavior can be added only once to an element class. | ||
| + | |||
| + | ====== Element Class Properties ====== | ||
| + | |||
| + | Element class properties have the prefix '' | ||
| + | |||
| + | ===== flags ===== | ||
| + | |||
| + | List of initially set flags. | ||
| + | |||
| + | * Full name: '' | ||
| + | * Type: list | ||
| + | * Default Value: empty list | ||
| + | * Example (*.deeclass) <code xml>< | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | ====== Behavior Tree Actions ====== | ||
| + | |||
| + | This behavior adds these behavior tree actions if behavior tree is present. | ||
| + | |||
| + | ===== flags.update ===== | ||
| + | |||
| + | Update flags. Action always succeeds. | ||
| + | |||
| + | ^Parameter^Value^Description^ | ||
| + | |set|string|Set named flag.| | ||
| + | |clear|string|Clear named flag.| | ||
| + | |||
| + | This is an example of setting a flag: | ||
| + | <code xml> | ||
| + | <action name=' | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | This is an example of setting and clearing a flag in the same action: | ||
| + | <code xml> | ||
| + | <action name=' | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== flags.check ===== | ||
| + | |||
| + | Check one or more flag parameters. Action succeeds if all parameter values match their respective flag state otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a flag matches (or not). | ||
| + | |||
| + | ^Parameter^Value^Description^ | ||
| + | |flag|string|Flag to check.| | ||
| + | |set|'' | ||
| + | |wait| |If present action returns BTResult.running instead of BTResult.failed to wait until the checks are all fulfilled.| | ||
| + | |reset| |If present toggle the flag after the checks succeeded.| | ||
| + | |||
| + | This is an example of checking if a flag is set right now: | ||
| + | <code xml> | ||
| + | <action name=' | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | This is an example of waiting until a flag is set: | ||
| + | <code xml> | ||
| + | <action name=' | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | This is an example of waiting until a flag is set and then clearing it: | ||
| + | <code xml> | ||
| + | <action name=' | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ====== Behavior Tree Conditions ====== | ||
| + | |||
| + | This behavior adds these behavior tree conditions if behavior tree is present. | ||
| + | |||
| + | ===== flags.check ===== | ||
| + | |||
| + | Check flag parameters. Condition returns true if all parameter values match their respective flag state. This condition is typically used to run an action or sequence of actions as long as flag conditions are true. | ||
| + | |||
| + | ^Parameter^Value^Description^ | ||
| + | |flags.flag|string|Flag to check.| | ||
| + | |flags.set|'' | ||
| + | |||
| + | This is an example of using this condition: | ||
| + | <code xml> | ||
| + | <action name=' | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ====== State Machine Actions ====== | ||
| + | |||
| + | Same as [[# | ||
| + | |||
| + | ====== State Machine Conditions ====== | ||
| + | |||
| + | Same as [[# | ||
| + | |||
| + | ====== State Machine Events ====== | ||
| + | |||
| + | This behavior sends these state machine events. | ||
| + | |||
| + | ===== flags.set:< | ||
| + | |||
| + | Flag named '' | ||
| + | |||
| + | This is an example of a transition that runs if the flag " | ||
| + | <code xml> | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== flags.cleared:< | ||
| + | |||
| + | Flag named '' | ||
| + | |||
| + | This is an example of a transition that runs if the flag " | ||
| + | <code xml> | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ====== Required Behaviors ====== | ||
| + | |||
| + | This behavior requires no other behaviors. | ||
| + | |||
| + | ====== Optional Behaviors ====== | ||
| + | |||
| + | * [[behavior_behaviortree|ECBehaviorBehaviorTree]]: | ||
| + | * [[behavior_statemachine|ECBehaviorStateMachine]]: | ||
| + | |||
| + | ====== Persistency ====== | ||
| + | |||
| + | This behavior does support element class to be persistable (setPersistable). Set flags are persisted. | ||
| + | |||
| + | ====== API Documentation ====== | ||
| + | |||
| + | # | ||
| + | |||
| + | Since DragonScript Module Version '' | ||
| + | |||
| + | ====== Use Cases ====== | ||
| + | |||
| + | * Remember that an event has happened, for example that a character arrived at a target. | ||
| + | * Share a yes/no state between behavior trees and state machines of the same element. | ||
| + | * Wait until another part of the element sets a flag before continuing. | ||
| + | |||
| + | ====== Element Class Example ====== | ||
| + | |||
| + | This example defines an element which contains flags. | ||
| + | |||
| + | < | ||
| + | class MyElement extends BehaviorElementClass | ||
| + | public var ECBehaviorFlags flags | ||
| + | func new() | ||
| + | flags = ECBehaviorFlags.new(this) | ||
| + | end | ||
| + | end | ||
| + | </ | ||
| + | |||
| + | ====== Behavior Factory ====== | ||
| + | |||
| + | Using element class supporting adding behaviors the behavior can be added like this: | ||
| + | <code xml> | ||
| + | <?xml version=' | ||
| + | < | ||
| + | < | ||
| + | <!-- optional: add behavior trees. default adds all behavior trees. --> | ||
| + | <list name=' | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <!-- optional: add state machines. default adds all state machines. --> | ||
| + | <list name=' | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ====== Live Examples ====== | ||
| + | |||
| + | * [[https:// | ||