Weird error when using arrays

Started by
6 comments, last by WitchLord 3 years, 1 month ago

Hello,

I am suddenly having a problem with using arrays in AngelScript.

I have registered the standard array addon:

RegisterScriptArray(engine, true);

But when I try to create an array in AngelScript like this:

int[] fff = { 3, 5 };

I get the following error:

[02:27:33][Warning] main.as (6, 1): Data type can't be 'int[]'

I don't understand why this happens, even if I revert my codebase to a far point back, the problem still persists? It just suddenly appeared out of nowhere and I can't figure out why.

None

Advertisement

So I found out what caused it; The template specializations. Did I do it wrong? This is how I did them:

If I remove this code, it works again.

static void RegisterArrayTemplateSpecializations(asIScriptEngine* engine)
{
    // Int
    engine->RegisterObjectType("array<int8>", 0, asOBJ_REF);
    engine->RegisterObjectType("array<int16>", 0, asOBJ_REF);
    engine->RegisterObjectType("array<int>", 0, asOBJ_REF);
    engine->RegisterObjectType("array<int64>", 0, asOBJ_REF);
    // UInt
    engine->RegisterObjectType("array<uint8>", 0, asOBJ_REF);
    engine->RegisterObjectType("array<uint16>", 0, asOBJ_REF);
    engine->RegisterObjectType("array<uint>", 0, asOBJ_REF);
    engine->RegisterObjectType("array<uint64>", 0, asOBJ_REF);
    // String
    //engine->RegisterObjectType("array<string>", 0, asOBJ_REF);
    // Bool
    engine->RegisterObjectType("array<bool>", 0, asOBJ_REF);
    // Floating point
    engine->RegisterObjectType("array<float>", 0, asOBJ_REF);
    engine->RegisterObjectType("array<double>", 0, asOBJ_REF);
    // alt:V Entities
    engine->RegisterObjectType("array<Player@>", 0, asOBJ_REF);
    engine->RegisterObjectType("array<Vehicle@>", 0, asOBJ_REF);
    engine->RegisterObjectType("array<Entity@>", 0, asOBJ_REF);
    engine->RegisterObjectType("array<VoiceChannel@>", 0, asOBJ_REF);
    engine->RegisterObjectType("array<ColShape@>", 0, asOBJ_REF);
    engine->RegisterObjectType("array<Checkpoint@>", 0, asOBJ_REF);
    engine->RegisterObjectType("array<Blip@>", 0, asOBJ_REF);
}

None

If you don`t register the full object type, with factory functions, addref, release, etc then it cannot be used. Unless you have more code related to the registration of the template specialization, that is what is happening here. The compiler recognizes the type int[] but it cannot be used.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

WitchLord said:

If you don`t register the full object type, with factory functions, addref, release, etc then it cannot be used. Unless you have more code related to the registration of the template specialization, that is what is happening here. The compiler recognizes the type int[] but it cannot be used.

So I need to copy all of the code for the generic template array type registration, and just replace it with the specialized type?

None

Well, not copy the template array type exactly. The template specialization is basically a normal object type so you need to register is as such. It doesn't have to have the same behaviours/methods as the script array add-on (but of course if it doesn't you may need to explain to your users why some arrays function one way, and why others work in another way).

Note, if you don't really want anything different than the array add-on then you shouldn't register the template specialization.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

WitchLord said:

Well, not copy the template array type exactly. The template specialization is basically a normal object type so you need to register is as such. It doesn't have to have the same behaviours/methods as the script array add-on (but of course if it doesn't you may need to explain to your users why some arrays function one way, and why others work in another way).

Note, if you don't really want anything different than the array add-on then you shouldn't register the template specialization.

Okay, yeah I don't want to change anything. But I saw that in the documentation that it says that you should declare the template specializations for better runtime performance.

So it is actually not needed?

None

Only if you actually provide the implementation of the template specialization that provides the improved runtime performance. ?

I suggest you go with the default template first, and only if you find that you have a need to improve performance for a specific type, then only do you need to implement the template specialization.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement