In GDScript, conditional expressions require the condition to evaluate to a boolean (true or false). If your _evaluate_condition(node) function returns a non-boolean value, you'll need to convert it to a boolean to use it in a conditional expression. This can be achieved using the bool() function, which converts various types to their boolean equivalents.
Here's how you can refactor your code:
# Evaluate condition
var condition_result = bool(_evaluate_condition(node))
var next_node_id = node.true_node_id if condition_result else node.false_node_id
var next_node = _get_node_by_id(next_node_id)
In this refactored code, condition_result is explicitly converted to a boolean using bool(). This ensures that the conditional expression operates correctly, regardless of the original type returned by _evaluate_condition(node).
Alternatively, you can use an if-else statement:
# Evaluate condition
var condition_result = _evaluate_condition(node)
var next_node_id
if bool(condition_result):
next_node_id = node.true_node_id
else:
next_node_id = node.false_node_id
var next_node = _get_node_by_id(next_node_id)
This approach also ensures that condition_result is treated as a boolean, providing clarity and avoiding potential issues with non-boolean values.
For more details on GDScript's control flow and expressions, refer to the GDScript reference.