Advertisement

How to return specific script objects from native code?

Started by May 27, 2017 06:22 PM
1 comment, last by Geat_Masta 7 years, 6 months ago

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?

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());
  }
  // ...
}
Advertisement

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.

This topic is closed to new replies.

Advertisement