Using GDScript in Godot, I'd like to customize the string representation of a class using the default representation plus my own message. So, I'm just doing:
func _to_string():
var my_string = super.to_string()
my_string += " -> GREEN" if is_green else " -> RED"
return my_string
However, this results in a stack overflow because of infinite recursion. Also tried using (self as Object).to_string()
with the same result.
My first intention was, that you need to user super() instead of super.to_string(), but this does not work either.
The docs don't say much to that either so my solution would be to instead of using the base class, mimic what it does as a default:
here it says the default is "<ClassName#RID>"
So your overwrite would look like this:
func _to_string():
var format_string = "<%s#%s>"
var base_response = format_string % [get_class(),get_instance_id()]
base_response += " -> GREEN" if is_green else " -> RED"
return my_string