Module accessible object?
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.
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.
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.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
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
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
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".
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement