
Publisher
srcoloma
StrategyMachine
Implementation of a strategy machine for Godot Engine, similar to a state machine but less restrictive (godot 4.1+) Nodes: StrategyMachine StrategyController <- here the interactions Strategy <- here the concrete behavior The machine follows only one strategy, but other strategies can be turned on and off without relying on the machine knowing their state. The philosophy is that the controllers only know when to turn on, turn off, or switch strategies, and that the strategies only have concre...
This plugin has been mirrored from the Godot Asset Library.
The plugin author is in no way affiliated with Gadget.
If you are the author of this plugin and would like this mirror removed, please contact support@gadgetgodot.com.
Strategy-Machine
Implementation of a strategy machine for Godot Engine, similar to a state machine but less restrictive (godot 4.1+)
How to use
- add a new node
StrategyMachine
node as a child. - add a new node
StrategyController
as a child of theStrategyMachine
node and change the node name. - add a new node
Strategy
as a child of theStrategyMachine
node and change the node name. - extend a new script from
StrategyController
and implement behavior between strategies. - extend a new script from
Strategy
and implement the_enter_strategy
,_exit_strategy
methods.
StrategyController
func switch_strategy_to(strategy_name: String)
Turns off the current Strategy
and switches to the strategy with the specified name.
This function simplifies the use of the machine by abstracting access to the machine's strategies.
func enable_strategy(strategy_name: String)
Enables the Strategy
with the specified name, without affecting the rest of the strategies.
This function simplifies the use of the machine by abstracting access to the machine's strategies.
func disable_strategy(strategy_name: String)
Disables the Strategy
with the specified name, without affecting the rest of the strategies.
This function simplifies the use of the machine by abstracting access to the machine's strategies.
func toggle_strategy(strategy_name: String)
Enables or disables a specific Strategy
with the specified name.
This function simplifies the use of the machine by abstracting access to the machine's strategies.
Strategy
_enter_strategy()
Called when the strategy is enabled.
_exit_strategy()
Called when the strategy is disabled.
Example
extends StrategyController
func _ready():
switch_strategy_to("Strategy1")
extends Strategy
func _enter_strategy():
print("Strategy1 enabled")
func _exit_strategy():
print("Strategy1 disabled")