Sign in to follow this  

Module accessible object?

This topic is 3787 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'd like to be able to do something like the following. In C++ I have a GameObject object that should be made global to a module and then from the script be able to call functions on that object something like this: void scriptFunction() { GameObject.Foo(); } Is it possible to make an object accessible inside the module so it can be used in any function within that module? If so, how? Each module would then have their own specific GameObject object. If this is not possible, what would be the best way to register and pass a pointer to the object to the script function? The script should not be able to create its own instances of GameObject. So the script function would look something like this. void scriptFunction( GameObject& gameObject ) { gameObject.Foo(); } Thanks for any help with this. I'm new to AngelScript and this is probably very trivial but I have a hard time getting started.

Share this post


Link to post
Share on other sites
With configuration groups you can decide which modules see which global properties, however registered global properties are all in the same namespace, so you'll only be able to register one variable with the name GameObject.

If you allow the game object to support references, then you could have the script declare a global variable that is a handle to the GameObject. The application can then initialize this handle after the script has been built. This way you'll have what you asked for.

If you don't want to allow object handles for the GameObject, you can still do what you want by Registering the type with a zero size and no ADDREF/RELEASE behaviours. The script functions can still be declared to take a reference to the GameObject, and the application can pass in that reference with every call to a script function.

Share this post


Link to post
Share on other sites
There is only one GameObject per module so if I understand it correctly namespace conflicts should not happen. Assuming the name is global within the module and not the whole AS engine. Maybe I'm wrong on this one?

To explain in another way what I want to accomplish: There will be many GameObjects and each GameObject will have several contexts and functions within one module. Basically a script or scripts will be attached to a GameObject and that GameObject needs to be available in the functions for the attached script.

And Ideally I'd like to use this form

void scriptFunction()
{
GameObject.Foo();
}

So the GameObject would be available without having to pass it to every function.
Thanks

Share this post


Link to post
Share on other sites
Let's say you've got module "dave" and module "george". You can register two GameObject global properties with the names "GameObject_dave" and "GameObject_george". Then in module "dave" you can set a global named "GameObject" that references "GameObject_dave" and in "george" you can set a global named "GameObject" that refers to "GameObject_george".

Share this post


Link to post
Share on other sites

This topic is 3787 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.

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