Skip to content

Commit 8ef4e89

Browse files
author
kagenashi
committed
Fixed BTAlways and example scenes
1 parent cb4c5a6 commit 8ef4e89

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

addons/behavior_tree/src/behavior_tree.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extends Node
77
export(bool) var is_active: bool = false
88
export(NodePath) var _blackboard
99
export(NodePath) var _agent
10-
export(String, "Idle", "Physics") var sync_mode
10+
export(int, "Idle", "Physics") var sync_mode
1111
export(bool) var debug = false
1212

1313
var tick_result
@@ -61,10 +61,10 @@ func start() -> void:
6161
return
6262

6363
match sync_mode:
64-
"Idle":
64+
0:
6565
set_physics_process(false)
6666
set_process(true)
67-
"Physics":
67+
1:
6868
set_process(false)
6969
set_physics_process(true)
7070

addons/behavior_tree/src/blackboard.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ export(Dictionary) var data: Dictionary
1515

1616

1717

18+
1819
func _enter_tree() -> void:
1920
data = data.duplicate()
2021

2122

23+
2224
func _ready() -> void :
2325
for key in data.keys():
2426
assert(key is String)
@@ -29,7 +31,7 @@ func set_data(key: String, value) -> void:
2931

3032

3133
func get_data(key: String):
32-
if has_data(key):
34+
if data.has(key):
3335
var value = data[key]
3436
if value is NodePath:
3537
if value.is_empty() or not get_tree().get_root().has_node(value):

addons/behavior_tree/src/btnodes/decorators/bt_always.gd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ extends BTDecorator
33

44
# Executes the child and always either succeeds or fails.
55

6-
export(String, "fail", "succeed") var always_what
6+
export(int, "Fail", "Succeed") var always_what
7+
8+
onready var return_func: String = "fail" if always_what == 0 else "succeed"
79

810

911

@@ -13,4 +15,4 @@ func _tick(agent: Node, blackboard: Blackboard) -> bool:
1315
if result is GDScriptFunctionState:
1416
result = yield(result, "completed")
1517

16-
return call(always_what)
18+
return call(return_func)

addons/behavior_tree/src/btnodes/decorators/bt_guard.gd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extends BTDecorator
1313
export(bool) var start_locked = false
1414
export(bool) var permanent = false
1515
export(NodePath) var _locker
16-
export(String, "Failure", "Success", "Always") var lock_if
16+
export(int, "Failure", "Success", "Always") var lock_if
1717
export(NodePath) var _unlocker
1818
export(int, "Failure", "Success") var unlock_if
1919
export(float) var lock_time = 0.05
@@ -54,9 +54,9 @@ func lock():
5454

5555

5656
func check_lock(current_locker: BTNode):
57-
if ((lock_if == "Always" and not current_locker.running())
58-
or ( lock_if == "Success" and current_locker.succeeded())
59-
or ( lock_if == "Failure" and current_locker.failed())):
57+
if ((lock_if == 2 and not current_locker.running())
58+
or ( lock_if == 1 and current_locker.succeeded())
59+
or ( lock_if == 0 and current_locker.failed())):
6060
lock()
6161

6262

bt_example/agent.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ script = ExtResource( 2 )
1313
[node name="BehaviorTree" parent="." instance=ExtResource( 1 )]
1414
_blackboard = NodePath("../../Agent/Blackboard")
1515
_agent = NodePath("../../Agent")
16-
sync_mode = "Idle"
1716

1817
[node name="Label" type="Label" parent="."]
1918
anchor_right = 1.0

bt_example/ex_behavior_tree.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ wait_time = 2.0
3434

3535
[node name="Always succeed" type="Node" parent="BTSequence"]
3636
script = ExtResource( 1 )
37-
always_what = "Succeed"
37+
always_what = 1
3838

3939
[node name="Out of ammo\?" type="Node" parent="BTSequence/Always succeed"]
4040
script = ExtResource( 5 )

0 commit comments

Comments
 (0)