Hi again. Back with another snag.
Went searching through the forums, and this thread almost covers what I’m interested in.
Here is the issue: in angelscript, I have a Main.as that has a bunch of code (stolen from one of the samples) and Start() calls a SubscribeEvents() method, which calls SubscribeToEvent() to register some event handlers.
#include "Stuff.as"
void Start()
{
SubscriberToEvents();
}
void SubscribeToEvents()
{
SubscribeToEvent("KeyDown", "HandleKeyDown");
SubscribeToEvent("UIMouseClick", "HandleUIMouseClick");
SubscribeToEvent("Update", "HandleUpdate");
SubscribeToEvent("PostUpdate", "HandlePostUpdate");
}
There is more code in main.as, but I’m keeping it simple for clarity. Everything runs fine with things set up this way.
Now I want to move most of the code in Main.as, including the handlers and the SubscribeToEvents() method over into another class. Then Main.as will work mainly as an entry point, and I can instantiate that new class in Main.as instead:
#include "FPSGame.as"
void Start()
{
FPSGame@ game = FPSGame();
}
#include "Stuff.as"
class FPSGame
{
FPSGame()
{
SubscribeToEvents();
}
void SubscribeToEvents()
{
SubscribeToEvent("KeyDown", "HandleKeyDown");
SubscribeToEvent("UIMouseClick", "HandleUIMouseClick");
SubscribeToEvent("Update", "HandleUpdate");
SubscribeToEvent("PostUpdate", "HandlePostUpdate");
}
}
The scripts do compile and run, but none of the event handlers in FPSGame fire (HandleKeyDown, HandleUIMouseClick, etc…). Which of course is undesirable.
So SubscribeToEvent() has 3 modes of operating.
[ul]
[] ScriptInstance (not applicable here)[/]
[] Procedural (which is what is happening in the original Main.as)[/]
[] Proxy (which I’m fairly sure is applicable here)[/]
[/ul]
Now I’m not sure that the script object mentioned in that paragraph means a plain vanilla angelscript object (class), or a ScriptObject from Urho, which FPSGame could inherit from, although I’m not sure I want to do that (I tried that, and it didn’t work anyways). Maybe there is a special way to register the eventhandlers with that proxy object mentioned?
It seems like I should be able to use normal angelscript classes to build my application, and only use ScriptObject when those classes will be used in a ScriptInstance (which FPSGame never would be). Or maybe I’m wrong about that. But either way, I can’t get the events to work in the FPSGame class.