Jump to content
  • Advertisement
Sign in to follow this  
__ROB_D__

Passing Object by Ref/Pointer

This topic is 3849 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'm reckon this question must be asked all the time! But I'm having trouble getting AS to do what i'd like it to do. What I've got on My code side my game object class and my instances of the object
// C++
class GObject_c
{
int DataA;
float DataB;
void Update();
}

GObject_c Monsters[10];

Now I don't want AS to create instances of the object class I'd like to be able to pass by reference or pointer (Is this possible?) My goal is to be able to write AS the will update the GObject i.e.
// Angle Script
void UpdateMonster(GObject_c @Monster)
{
DataA = 12;
}

So what would be helpful is a simple example of how to do this? Thanks

Share this post


Link to post
Share on other sites
Advertisement
I believe you want this: Register an uninstanciable reference object

Basically you need to do this:


engine->RegisterObjectType("GObject", 0, asOBJ_REF);
engine->RegisterObjectBehaviour("GObject", asBEHAVE_ADDREF, "void f()", asMETHOD(GObject, AddRef), asCALL_THISCALL);
engine->RegisterObjectBehaviour("GObject", asBEHAVE_RELEASE, "void f()", asMETHOD(GObject, Release), asCALL_THISCALL);


By not registering the factory method AngelScript won't be able to instanciate any objects of the type.

If you don't want to implement reference counting for your GObject type (recommended, at least for debugging) then you can register the AddRef and Release behaviours using a dummy function that doesn't do anything.


void DummyFunc(void *) {}
engine->RegisterObjectBehaviour("GObject", asBEHAVE_ADDREF, "void f()", asFUNCTION(DummyFunc), asCALL_CDECL_OBJLAST);
engine->RegisterObjectBehaviour("GObject", asBEHAVE_RELEASE, "void f()", asFUNCTION(DummyFunc), asCALL_CDECL_OBJLAST);


Of course, then you won't know how many references AngelScript holds to your object.

Regards,
Andreas

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!