Bit of a discussion, as I haven't decided what would be the best way to go about implementing this yet.
Currently using ScriptInstance only the ScriptObject defined when created can be used to receive events, however if I wanted to do something like the following, where Bar is instantiated from the C++ code in ScriptInstance:
class Foo : ScriptObject
{
...
SubscribeToEvent(listbox,"SelectionChanged","HandleListBoxSelectionChanged");
...
HandleListBoxSelectionChange(StringHash eventType, VariantMap& eventData) { }
...
}
class Bar : ScriptObject
{
...
Foo@ foo;
...
Start()
{
foo = Foo();
}
}
It will never work because the ScriptInstance will only look for the method in Bar. There are work arounds in we can have Bar have all the event listeners or have global functions to handle the events. It would help clean-up and improve the angelscript code if in some method we could allow pure script classes which aren't instantiated through the ScriptInstance to receive events as well.
I have some ideas based around the
receive script classes example in the docs, so I think allowing the scripts to do something like this:
SubscribeToEvent(this,listbox,"SelectionChanged","HandleListBoxSelectionChanged");
Should be possible but its then comes the handling in ScriptInstance and ensuring the correct object receives the correct event, if ScriptInstance is even the right place to handle this but I expect it should be since we'd want to associate the script classes with the ScriptInstance which instantiated the original class.
Any thoughts or ideas would be good to hear on the concept.