• Advertisement
Sign in to follow this  

How to return specific script objects from native code?

Recommended Posts

I'm doing this: http://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_inheritappclass.html And I need to be able to return a pointer to the script class from a call to a native function, (e.g. getting an object in proximity to the one that called the method).  But i can't figure out how to do this, I keep getting the error: "Identifier 'GameObject' is not a data type in global namespace"

I tried registering all the native methods except the ones that return pointers to script classes, the registering those script classes, then registering the remaining native methods, but that doesn't change the error.

What do I do?

 

 

Share this post


Link to post
Share on other sites
Advertisement

The application cannot register any entities that rely on something only defined in scripts (even if said script is always loaded) so the straightforward approach is not an option. There are many possible workarounds though. The best one I can think of is to register an interface for GameObject to inherit from. AngelScript doesn't allow script classes to inherit from application-registered classes, but it does allow them to inherit from interfaces, and handles to interfaces can be returned, e.g.

In the application:

engine->RegisterInterface("GameObjectInterface");
engine->RegisterObjectMethod("GameObject_t", "GameObjectInterface@ getNearestObject()", asMETHOD(InternalGameObject, getNearestObject), asCALL_THISCALL);

In the shared script section:

shared abstract class GameObject : GameObjectInterface {
  // ...
  GameObject@ getNearestObject() {
    return cast<GameObject>(m_obj.getNearestObject());
  }
  // ...
}
Edited by Sir Ementaler

Share this post


Link to post
Share on other sites

I made that change and got it to finish loading the native classes, but even though I'm still loading in the scripted version prior to loading any script files, and i marked the class as shared, the files give me the same "'GameObject' is not a data type in the global namespace" error.

EDIT: nevermind i found it.

Edited by Geat_Masta

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  

  • Advertisement