Couple of simple questions about programing in angelscript
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.
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
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
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
Popular Topics
Advertisement
Recommended Tutorials
Advertisement