How to identify operators for specific classes? (OOP)

Question

Hi, I’m building a class of data to keep the most used type in my game, it’s all fine but I need to specify change or logical operators, for example when I use == the compiler checks a specific attribute in the type and not the whole of it, or when I use new_type_var -= 20 it does exactly what it should, I haven’t found anything about this. um, but I think it should be possible, as a lot of classes have operators like this (you can check the documentation).
Does anyone have any information on how to do it? I think it should be a function with a special name…

As far as I can see, there is nothing like that built-in currently.
You can make your own function equals() that compares the values of the underlying properties of the object instead of the reference.

Yes, but I’m looking for a way to use first_var == second_var instead of first_var.equals(second_var).
Or find ways to link this to it…

I know what you’re aiming for, but I don’t think that’s possible currently in GDScript.
You can try doing that in C#, but I haven’t tried it, so can’t say if this will work.

And I think that even if you do it this way it will work in C# scripts only and not GDScript.
You can open a proposal on Godot GitHub if you see value in that, although I suspect it might be harder (if not impossible) to implement with the non-static language.

1 Like