Hey,
I recently started porting my engine over to AngelScript and I have a couple of questions. Scripts are added to game objects by attaching a script component to the object type, kind of how unity works. I want the script writers to be able to declare global variables freely without touching other scripts, so I am planning to use one module per script component. The contexts are pooled and there is only ever one script engine (or two, if I go with one engine per network node, of which there may be two per process).
Ideally I would like to expose global functions on a per-module basis, so I could call the "getParentName()" global function and it would give me the name of the game object the script component belongs to. However, as global functions seem to be registered on a per-engine basis I figured I would just expose the interface to the game object through a class that is only ever created and destroyed by the C++ code. So instead I could do something like "gParentGameObject.getName()" to get the name of the parent.
Seem good so far? Anything that seems crazy? If not let's get on with the questions:
I can expose the game object class with the flags set to "asOBJ_REF | asOBJ_NOCOUNT" and leave out the factory behavious registration, right? In the script, will I still pass around handles to the object or should I use references?
And how should I go about assigning the value of the "gParentGameObject" global variable? the assignment should happen right after the script component has been created as part of the game object instantiation. I have seen some examples using GetAddressOfGlobalVar() and casting to the correct type on the C++ side, but I am unsure of the exact syntax with objects registered with the NOCOUNT flag. The object is always guaranteed to be created before any script code for script component is run, and it is also guaranteed to outlive any script execution.
Thanks! And thank you four AngelScript. Hands down the nicest-to-use Application<->Script interface I have seen.