Fix BTSetVar succeeding and setting variable to null when value parameter doesn't exist on the Blackboard

This commit is contained in:
Serhii Snitsaruk 2023-09-02 14:16:52 +02:00
parent 16b25fa760
commit fe551e0299
1 changed files with 7 additions and 3 deletions

View File

@ -11,6 +11,7 @@
#include "bt_set_var.h"
#include "modules/limboai/blackboard/bb_param/bb_param.h"
#include "modules/limboai/util/limbo_utility.h"
#include "core/variant/callable.h"
@ -24,9 +25,12 @@ String BTSetVar::_generate_name() const {
}
int BTSetVar::_tick(double p_delta) {
ERR_FAIL_COND_V_MSG(variable.is_empty(), FAILURE, "BBSetVar: `variable` is not set.");
ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BBSetVar: `value` is not set.");
get_blackboard()->set_var(variable, value->get_value(get_agent(), get_blackboard()));
ERR_FAIL_COND_V_MSG(variable.is_empty(), FAILURE, "BTSetVar: `variable` is not set.");
ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTSetVar: `value` is not set.");
Variant error_result = SNAME("Error: BTSetVar failed to get value!");
Variant result = value->get_value(get_agent(), get_blackboard(), error_result);
ERR_FAIL_COND_V_MSG(result == error_result, FAILURE, "BTSetVar: Failed to get parameter value. Returning FAILURE.");
get_blackboard()->set_var(variable, result);
return SUCCESS;
};