I need to transfer an array of tiles from C++ to Angelscript, I have tried adding a function that returns an std::vector but it returns this error
Failed in call to function 'RegisterGlobalFunction' with 'array<DumbTile> GetTilesAt(int x, int y)' (Code: asINVALID_DECLARATION, -10)
my code:
std::vector<DumbTile> GetTilesAt(int x, int y) {
std::vector<DumbTile> output;
for (DumbTile t : tiles) {
if (t.x == x && t.y == y) {
output.push_back(t);
}
}
return output;
}
engine->RegisterGlobalFunction("array<DumbTile> GetTilesAt(int x, int y)", asFUNCTIONPR(GetTilesAt, (int, int), std::vector<DumbTile>), asCALL_CDECL);
Is
DumbTile
registered beforeGetTilesAt()
registration?Is
array<T>
registered beforeGetTilesAt()
registration?Both needs to be registered before you can register your function.
Are you using stock array implementation (
sdk/add_on/scriptarray/
) or your own,std::vector<>
-based implementation? When using stock addon, application must convertstd::vector
toCScriptArray
first, as angelscript can't really do that on its own due to way how arrays works.There is obvious alternative - switch from using
std::vector
toCScriptArray
everywhere where you want scripts to access data, but this might be annoying.Example
std::vector<Object*> <-> CScriptArray*
conversionCode is bit old but i think it should still work, even if it begs for some refresh.