diff --git a/bt/tasks/utility/bt_call_method.cpp b/bt/tasks/utility/bt_call_method.cpp
index 555bd6e..3640685 100644
--- a/bt/tasks/utility/bt_call_method.cpp
+++ b/bt/tasks/utility/bt_call_method.cpp
@@ -54,15 +54,16 @@ PackedStringArray BTCallMethod::get_configuration_warnings() const {
}
String BTCallMethod::_generate_name() const {
- int argument_count = include_delta ? args.size() + 1 : args.size();
- Array final_args;
- if (include_delta) {
- final_args.push_back("delta");
+ String args_str = include_delta ? "delta" : "";
+ if (args.size() > 0) {
+ if (!args_str.is_empty()) {
+ args_str += ", ";
+ }
+ args_str += Variant(args).get_construct_string().trim_prefix("[").trim_suffix("]");
}
- final_args.append_array(args);
return vformat("CallMethod %s(%s) node: %s",
(method != StringName() ? method : "???"),
- (argument_count > 0 ? Variant(final_args).get_construct_string().trim_prefix("[").trim_suffix("]") : ""),
+ args_str,
(node_param.is_valid() && !node_param->to_string().is_empty() ? node_param->to_string() : "???"));
}
@@ -107,9 +108,14 @@ void BTCallMethod::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_include_delta", "p_include_delta"), &BTCallMethod::set_include_delta);
ClassDB::bind_method(D_METHOD("is_delta_included"), &BTCallMethod::is_delta_included);
- ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "method"), "set_method", "get_method");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "BBNode"), "set_node_param", "get_node_param");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "include_delta"), "set_include_delta", "is_delta_included");
- ADD_PROPERTY_DEFAULT("include_delta", false);
+ ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "method"), "set_method", "get_method");
+ ADD_GROUP("Arguments", "args_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "args_include_delta"), "set_include_delta", "is_delta_included");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "args"), "set_args", "get_args");
+
+ ADD_PROPERTY_DEFAULT("args_include_delta", false);
+}
+
+BTCallMethod::BTCallMethod() {
}
diff --git a/bt/tasks/utility/bt_call_method.h b/bt/tasks/utility/bt_call_method.h
index 03dcc12..a73cac4 100644
--- a/bt/tasks/utility/bt_call_method.h
+++ b/bt/tasks/utility/bt_call_method.h
@@ -46,6 +46,8 @@ public:
bool is_delta_included() const { return include_delta; }
virtual PackedStringArray get_configuration_warnings() const override;
+
+ BTCallMethod();
};
#endif // BT_CALL_METHOD
diff --git a/doc_classes/BTCallMethod.xml b/doc_classes/BTCallMethod.xml
index 6d0cbe4..a073b5e 100644
--- a/doc_classes/BTCallMethod.xml
+++ b/doc_classes/BTCallMethod.xml
@@ -13,7 +13,7 @@
The arguments to be passed when calling the method.
-
+
Include delta as a first parameter and shift the position of the rest of the arguments if any.
diff --git a/tests/test_call_method.h b/tests/test_call_method.h
index c04a40d..dad3401 100644
--- a/tests/test_call_method.h
+++ b/tests/test_call_method.h
@@ -20,6 +20,7 @@
#include "modules/limboai/bt/tasks/utility/bt_call_method.h"
#include "core/os/memory.h"
+#include "core/variant/array.h"
namespace TestCallMethod {
@@ -64,6 +65,52 @@ TEST_CASE("[Modules][LimboAI] BTCallMethod") {
CHECK(cm->execute(0.01666) == BTTask::SUCCESS);
CHECK(callback_counter->num_callbacks == 1);
}
+ SUBCASE("With arguments") {
+ cm->set_method("callback_delta");
+
+ SUBCASE("Should fail with 0 arguments") {
+ cm->set_include_delta(false);
+ cm->set_args(Array());
+ ERR_PRINT_OFF;
+ CHECK(cm->execute(0.01666) == BTTask::FAILURE);
+ ERR_PRINT_ON;
+ CHECK(callback_counter->num_callbacks == 0);
+ }
+ SUBCASE("Should fail with too many arguments") {
+ cm->set_include_delta(true);
+ Array args;
+ args.push_back(0.2);
+ cm->set_args(args);
+ ERR_PRINT_OFF;
+ CHECK(cm->execute(0.01666) == BTTask::FAILURE);
+ ERR_PRINT_ON;
+ CHECK(callback_counter->num_callbacks == 0);
+ }
+ SUBCASE("Should fail with a wrong type arg") {
+ cm->set_include_delta(false);
+ Array args;
+ args.push_back("wrong_data");
+ cm->set_args(args);
+ ERR_PRINT_OFF;
+ CHECK(cm->execute(0.01666) == BTTask::FAILURE);
+ ERR_PRINT_ON;
+ CHECK(callback_counter->num_callbacks == 1);
+ }
+ SUBCASE("Should succeed with delta included") {
+ cm->set_include_delta(true);
+ cm->set_args(Array());
+ CHECK(cm->execute(0.01666) == BTTask::SUCCESS);
+ CHECK(callback_counter->num_callbacks == 1);
+ }
+ SUBCASE("Should succeed with one float arg") {
+ cm->set_include_delta(false);
+ Array args;
+ args.push_back(0.2);
+ cm->set_args(args);
+ CHECK(cm->execute(0.01666) == BTTask::SUCCESS);
+ CHECK(callback_counter->num_callbacks == 1);
+ }
+ }
memdelete(dummy);
}