Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | BusSeatProgrammer |
Hello there,
I am having some troubles when trying to use a method with a Godot’s Array which was passed from GDScript to my C++ module.
In the C++ code below, I am trying to read the size of arrayFoo[1][2] which is a monodimensional array.
Array FooNode:FooFunction(Array arrayFoo)
{
int arraySize = arrayFoo[1][2].size(); // This lines gives an error
// Code continues
Visual Studio Code throws immediately an error once I have finished typing the line.
more than one conversion function from "Variant" to a built-in type applies: -- function "Variant::operator Object *() const" (declared at line 216 of "/_Godot_CPP_VSCode/Godot-CPP-Linux-VSCode-Full-Setup/source/godot/core/variant.h") -- function "Variant::operator Node *() const" (declared at line 217 of "/_Godot_CPP_VSCode/Godot-CPP-Linux-VSCode-Full-Setup/source/godot/core/variant.h") -- function "Variant::operator Control *() const" (declared at line 218 of "/_Godot_CPP_VSCode/Godot-CPP-Linux-VSCode-Full-Setup/source/godot/core/variant.h")C/C++(418)
In the variant header file I see these three lines in position 216, 217 and 218.
operator Object *() const;
operator Node *() const;
operator Control *() const;
First question: How can I choose the right conversion from the three listed? Or is there another way to get the size? Also, why the error concerns variant.h while I am using an Array? Shouldn’t it be an error coming from Array.h?
I have also noted that if I change the line to
int arraySize = arrayFoo[1].size();
Now the squiggly lines appears below size() with the error
class "Variant" has no member "size"C/C++(135)
That’s kinda odd, as I have not defined the arrayFoo anywhere in the C++ module and, since it has been passed, then this could possibly be an array of variants.
Second question: what am I missing?
Unfortunately I couldn’t find any documentation on the topic and going through the source code confused me even further.
Does anyone have an idea on how to perform this simple operation, please?
Thanks