Jump to content
  • Advertisement
Sign in to follow this  
Geat_Masta

How to return specific script objects from native code?

This topic is 418 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

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
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!