🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to register an array member in class ?

Started by
5 comments, last by zopenge 16 years, 3 months ago
class Box { public: Vector3 mVectors[8]; }; how can I register mVector3 ? thanks !!
Advertisement
Until AngelScript supports static arrays, you can register this by registering your own array type, which you then register as the member of the Box class:

RegisterObjectType("vec3arr8", sizeof(Vector3[8]), asOBJ_VALUE | asOBJ_POD | asOBJ_CLASS);RegisterObjectBehaviour("vec3arr8", asBEHAVE_INDEX, "Vector3 &f(uint)", asFUNCTION(vec3arr8_index), asCALL_CDECL_OBJLAST);...Vector3 *vec3arr8_index(unsigned int idx, Vector3 *arr){  if( idx >= 8 )     asGetActiveContext()->SetException("out of bounds");  return &arr[idx];}

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

r = engine->RegisterObjectProperty( "Box", "Vector3@[] mVectors(8)", offsetof( ScriptBox, mBox.mVectors ) );

can I register the array like this ?

No, unfortunately not. The built-in array object is not compatible with C++ static arrays.

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

Oh, Will the next version support for this ?

It's a bit complex for using it :)
I wish I could say yes, but the changes are too complex for me to be able to implement this for the next version.

If you can live without the array being an array in the script you can also register it as 8 separate properties, e.g:

RegisterObjectProperty("box", "float m1", offsetof(Box, mVectors));
RegisterObjectProperty("box", "float m2", offsetof(Box, mVectors) + 4);
RegisterObjectProperty("box", "float m3", offsetof(Box, mVectors) + 8);
etc

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

OK~~~ But I am still waitting for the new feature of it ~~ :P

Thanks for your gooooood work !

This topic is closed to new replies.

Advertisement