Hello,
I know I asked a similar question before but I still have one doubt.
So, my game has N states (individual screens like pause, menu, game etc) and each one lives in its own module and communicates with other states exclusively using a central queue, so all information gets to the destination indirectly.
But now, I also added behaviors to the engine, where each behavior is a script that controls an entity's behavior. For example, one behavior script might give an artificial intelligence to the character, another just make it follow a path etc.
For now, each behavior is a custom class, such as class MyBehavior : Behavior {}, and is also living in its own module and loaded from its own script file, which works fine to deal with its attached entity and give it behavior. However, now I need that my game state script is able to retrieve data from any of this behaviors currently instanced, like:
// this is the game state script
behaviorClass@ behaviorObject = cast<behaviorClass@>( GetBehavior("entityName", "behaviorClass") );
behaviorObject.x = ; // set or get variables declared in the external file of the given behavior
I'd like to add that the behaviors are hot reloadable, so I basically shut them down and re create them once the script source has changed, in order to have the most recent version running in the game without re-running the process. Is there a way to do something similar to this with AngelScript? I am not sure if the game state script module could either dynamically bind to these external behavior classes or just remove and recompile the code sections respective to the behavior scripts so they are in scope, while operating on instanced objects of behavior classes created in the other module.
As a second question, just wanted to ask if there is a way to associate member variables with the pure angelscript interfaces. I basically want that when I implement a new behavior, as it inherits the interface Behavior, it would automatically inherit a member Entity@ attachedEntity, so even if my custom behavior class has no members it still knows about which entity that instance is attached to. I am asking as I didn't see any C++ api function to do this, interfaces seemed to only be able to define the virtual methods and actual interface name,
The solution I thought about was to define myself a base class that is actually a angelscript class rather than an interface, this way I could do anything to it and pre-implement functions etc, is this the way to go?
Is there any chance you can implement in the future some kind of explicit and/or implicit conversion mechanism when calling a function? Like MyBehavior@ a = getBehavior<MyBehavior>() or have it return instead an abstract handle to the base type that can be automatically casted to the expected type of 'a'? I am talking about doing these with only script classes here