Skip to main content
GameDev.net gamedev.net
🔒 Locked

Can't register array property

Started by andrew1b Sep 14, 2010 at 6:27 PM 1 replies 1.2k views
Original Post
andrew1b
andrew1b
The RegisterObjectProperty method is returning -10 (invalid declaration) when I try registering a float array as property:

	int r;	r = pASEngine->RegisterObjectType("matrix4x4", sizeof(Matrix4x4), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CA); assert(r >= 0);	// Register the object properties	r = pASEngine->RegisterObjectProperty("matrix4x4", "float e[16]", offsetof(Matrix4x4, e)); assert(r >= 0);


Is it impossible to register array members?
...
WitchLord
WitchLord
Not like this. Arrays in AngelScript are dynamic objects, and not compatible with C++ static arrays. I am planning improvements to allow this to be done in the future, but it will be a while before I get it implemented.

In the meantime you can register the elements of the matrix as individual properties.

r = pASEngine->RegisterObjectProperty("matrix4x4", "float e0", offsetof(Matrix4x4, e[0])), assert( r >= 0 );r = pASEngine->RegisterObjectProperty("matrix4x4", "float e1", offsetof(Matrix4x4, e[1])), assert( r >= 0 );...


Or write a simple function to allow access to the elements. The function can be implemented as a global function so you don't have to change the C++ implementation of the Matrix4x4 class.

r = pASEngine->RegisterObjectMethod("matrix4x4", "float &e(uint)", asFUNCTION(AccessMatrixElement), asCALL_CDECL_OBJLAST); assert( r >= 0 );float *AccessMatrixElement(asUINT n, Matrix4x4 &m){  if( n > 16 )  {    asIScriptContext *ctx = asGetActiveContext();    ctx->SetException("Index out of bounds");    return 0;  }  return m.e[n]; }
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
andrew1b
andrew1b
Thanks Andreas. I really forgot that arrays in AngelScript won't work this way. Anyway, there are several ways to solve it. It won't be a problem.
...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.