Open markwiering opened 2 years ago
I never created a module before, so I may be wrong, but I think you have to return Ref<Beurk>
Ref<Breuk> Breuk::maak(int x, int y) {
Ref<Breuk> b;
b.instantiate();
b->a = x;
b->b = y;
return b;
} // returns a class instance
this compiles without problem.
I took this as an example: https://github.com/godotengine/godot/blob/13d99d1676a72ffa529ffb7cee7ce97582fb42f1/scene/main/scene_tree.cpp#L1857-L1870
Now, I don't know what this module is supposed to do, but I would suggest :
Thank you, @gotnospirit. Your implementation worked, though I had to change b.instantiate();
into b.instance();
to make it work.
This class is about fractions. I also have a class with Xs and a formula class (where the formula class contains a vector of Xs). I plan to port them all to GDscript, because I am working on an educative cat game that teaches the children (ranging from 12 to 18 years old) mathematics. On each level switch, you are prompted to a screen resembling a Commodore64 (since the cat carries a Commodore64 with him) where you need to solve some mathematical equations in the forms of several multiple choice questions.
I have all those questions implemented in C++, but now I need to port them to GDscript. I am trying to accomplish that with C++ modules, such that I can create a instance of each of this class (fraction, Xs and formula) in GDscript.
But now I hope that I can also port the operator overloaders to GDscript, because if that is not possible, then I need a different approach. Then I need to make bounded C++ functions that generate the question and the correct answer by themselves. This will make the mathematical less flexible (having to recompile the entire engine every single time I want to adjust the difficulty of a question), but it is possible nonetheless in case I cannot bind the operator overloaders to GDscript.
Right now, I am going to rewrite the class functions to make it such that they return Ref<Breuk>
instead of Breuk
. :-)
I was just trying to solve the compile problem but, before putting Ref<>
everywhere, maybe you could have a look to classes like core\math\vector2
Good luck :)
I will have a look at core/math/vector2, @gotnospirit ! Thank you for the suggestion! :smile:
Godot version
3.6 beta custom build
System information
MX Linux 21.2 64-bit, Mesa Intel(R) Xe Graphics (TGL GT2)
Issue description
When creating a C++ module where the class binds a function that returns a class instance, Godot gives a compilation error. This error is not given when not binding this function.
The error given:
The error in image form:
![foutmeldingGodotC++module2](https://user-images.githubusercontent.com/5214209/188859479-4f56afa0-9a67-4ba3-8669-63c312acdc1c.png)
The piece of code that causes this error.
![dezeverbindinggeeftdefout](https://user-images.githubusercontent.com/5214209/188859475-f1166339-8e59-44b7-9265-07fab4298b80.png)
The module that causes this error:breuk.zip
Steps to reproduce
Breuk Breuk::maak(int x, int y) { return Breuk(x, y); }
ClassDB::bind_method(D_METHOD("maak", "x", "y"), &Breuk::maak);
Now go to the main folder of the cloned repository of Godot and run
scons -j8 platform=x11
to compile the project.You will get a compilation error. This compilation error goes away when outcommenting the binding, or when modifying the bound function in such a way that it returns one of the default types (integer, float, bool, string, char etcetera) rather than return a class instance.
Minimal reproduction project
This error is not occurring when Godot is running, but then Godot is compiling. Therefore, I hereby include the module that evokes this compilation error: breuk.zip