Advertisement

Two questions about arrays

Started by June 01, 2011 11:36 AM
0 comments, last by WitchLord 13 years, 8 months ago
1) Is there any way, to register native C++ static arrays?
[s]2) I followed steps from this example code: http://www.angelcode...ddon_array.html to register CScriptArray containing Block_Vector's (it's my custom class). How should I register that kind of array as a global property? I did it this way: [/s]

CScriptArray* resultsV;
RegisterScriptArray(ASM->GetEngine()->m_ptr, true);

asIObjectType* t = ASM->GetEngine()->m_ptr->GetObjectTypeById(ASM->GetEngine()->m_ptr->GetTypeIdByDecl("array<Vector>"));
resultsV = new CScriptArray(1000000, t);
for( int i = 0; i < 1000000; i++ )
{
Block_Vector** p = static_cast<Block_Vector**>(resultsV->At(i));
*p = new Block_Vector(0.0f, 0.0f, 0.0f, 0.0f);
}

ASM->GetEngine()->m_ptr->RegisterGlobalProperty("array<Vector> g_resultsV", &resultsV);

When I use g_resultsV in script in loop, this statement causes crash: g_resultsV[ no ].
It looks like my CScriptArray is totally wrong and uninitialized, it's buffer is NULL.
What should I fix in my code?

I'm using the latest 2.20.3 version of Angel Script.

EDIT:
Ad 2) It was stupid mistake, it was here:
ASM->GetEngine()->m_ptr->RegisterGlobalProperty("array<Vector> g_resultsV", &resultsV);
I passed pointer to pointer, working version looks like this:
ASM->GetEngine()->m_ptr->RegisterGlobalProperty("array<Vector> g_resultsV", resultsV);

EDIT2:
It still crashes :/.

EDIT3:
Again... it was my mistake :).
Working code:
Block_Vector* p = static_cast<Block_Vector*>(resultsV->At(i);
p = new Block_Vector(0.0f, 0.0f, 0.0f, 0.0f);

But my question number 1 is still open :).
The only way to directly register a static array, is as if it was a fixed size structure, for example a float[3] can be registered with RegisterObjectType("float3", sizeof(float[3]), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS);. Of course this only works if the array is always the same size.

If the array is a member of a class, it is probably easiest to use property accessors to expose the array itself rather than trying to register a type to represent the array.








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