Advertisement

Passing Object by Ref/Pointer

Started by March 06, 2008 10:03 AM
1 comment, last by __ROB_D__ 16 years, 11 months ago
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
Rob Davies - Programmer @ [XWired Games]
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

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

Advertisement
WitchLoad,

Thank You, I'll give that I try and see how I get on.
Rob Davies - Programmer @ [XWired Games]

This topic is closed to new replies.

Advertisement