I need some help.
I've been using SendModEvent and RegisterForModEvent without problems. And then suddenly it seems to have stopped working. Clearly, I must have changed something, but I can't see it. Debug statements show that the registration happens and the event gets sent. It's just that the handler event never gets called.
So I created a test script to see how it should work. That didn't work either. This is what I did:
- I created a test cell. It has a floor, a button and a duplicate of Ancarno.
- I added a quest. The quest is start enabled and has a seq file
- The quest has properties for the button and for the Ancarno clone
- In the OnInit method, the quest registers for "Button_Pressed" events
- The button has an OnActivate event handler that raises "Button_Pressed"
This is the button script
Scriptname SSG_Test_Button extends ObjectReference Event OnActivate(ObjectReference akActionRef) string ev_name = "Button_Pressed" debug.MessageBox("Sending event '"+ev_name+"'") SendModEvent(ev_name)EndEvent
And this is the quest script.
Scriptname SSG_Test_Script extends Quest Actor Property Ancarno Auto ObjectReference Property button Auto event OnInit() string ev_name = "Button_Pressed" debug.MessageBox("Quest: Registering for event '"+ev_name+"' from "+button) button.RegisterForModEvent(ev_name, "OnPressButton") ; Grah! Vegetables!EndEventEvent OnPressButton() debug.MessageBox("Quest: OnPressButton event received") Ancarno.kill()EndEvent
Can anyone see what I'm doing wrong? I suspect it's something basic, but I can't see it for the life of me.
[edit]
I'll just add that I'm aware that mod events need to be re-registered on loading a game, but since I'm testing this all in one session that didn't seem strictly relevant. I've also tested this both by coc-ing from the menu and using LAL to start a new character. Same result both cases,
[edit]
Don't you hate it when you see the problem five minutes after you ask for help?
Problem was twofold. First of all, I was writing "button.RegisterForModEvent(...)" thinking that I was asking the button to send events to the calling quest script. Turns out it's not a 1:1 relationship. Mod events are broadcast and anyone can pick them up. So what I was actually doing was registering the button to get its own events.
I did try it without the "button." as per the docs, but that didn't work. Reason for that is that I had the wrong args on the event callback so the call was failing.
Problems corrected, I press the button and a sneering Thalmor mage dies painfully. I should be able to make my mod work again, now.
Thanks for listening
[edit]
Anyone know how to add "(Solved)" to the title? I don't seem to be able to edit the subject line.