Sign in to follow this  

Multi-dimensional arrays?

This topic is 2854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I recently discovered AngelScript, and I'm working on integrating it into a C++ game framework. I was wondering with Angelscript supports multi-dimensional arrays? I couldn't see them mentioned in the docs. Thanks,

Share this post


Link to post
Share on other sites
use a one dimensional array of length N*M and handle it as if it is it two dimesional.

index(a,b){ return array[a*M+b]}

not the answer to your question though.. sorry

Share this post


Link to post
Share on other sites
AngelScript has built-in support for multidimensional arrays, or rather, arrays of arrays. These are declared as follows:


// Declare a 3x3 matrix pre-initialized
int[][] multiarray = {{1,2,3},{1,2,3},{1,2,3}};

// Declare an empty array
int[][] multi2;

// Resize it to desired dimension
multi2.resize(3);
multi2[0].resize(3);
multi2[1].resize(3);
multi2[2].resize(3);


You can also register your template object type to function exactly the way you want. You can take a look at the add_on/scriptarray/scriptarray.cpp for an example on how that can be done. It registers a single dimensional array template, but you can easily expand it to multidimensional if you want.

Regards,
Andreas

Share this post


Link to post
Share on other sites

This topic is 2854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this