Sign in to follow this  
jal_

Couple of simple questions about programing in angelscript

Recommended Posts

Hey, I wonder how a couple of things can be done from angelscript. First of all, excuse me if they sound dumb. I'm more a C than a C++ coder and don't really have a big mentallity for object oriented coding. K, on the questions, they are: Say I declare an array of objects of an angelscript declared class, lets say class myClass: myClass[] myclassobjects( MAX_OBJETS ); And I get an object handle of one of the objects in the array. Is it possible, from inside the object, to find out what is it index in the array? In C I would simply subtract the object pointer from the array pointer, would some similar trick work in AS? And second question. All inside AS scripting. Say I declare a class, and I want this class to contain an object handle where I can store the handle to another AS declared class object, but not be of a specific class, but able to store it of any class (with casting or whatever). Is this possible? Thnx in advance.

Share this post


Link to post
Share on other sites
Unfortunately you will need to search array for the object pointer in order to find its index. This is because the objects are not allocated in a single linear buffer, instead each object has its own memory buffer. This is necessary so that objects can survive even if the array itself is destroyed.

If you want to be able to store any class then I suggest you register the "any" add-on, which permits the storage of any type. However, if you just want to be able to store a given family of objects, then I suggest you define an interface for that family and then store a handle to that interface. All classes in that family should then implement that interface.

Regards,
Andreas

Share this post


Link to post
Share on other sites

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