xOBSE
xOBSE copied to clipboard
ExitToMainMenu event handler doesn't activate when expected
I initially reported this in the Bethsoft forum thread but feel that I need to create an issue.
I have tried to use the ExitToMainMenu event handler in my mod but it doesn't appear to do anything at all. Eventually, I created a test plugin that can be downloaded from here: https://www.4shared.com/file/4bq_MTVIba/ExitToMainMenu_Event_Handler_t.html It uses the following scripts:
ScriptName XjTestExitToMainMenuEventHandlerFunctionScript
Begin Function {}
MessageBox "ExitToMainMenu event has occured."
End
ScriptName XjTestExitToMainMenuEventHandlerQuestScript
Short bEventHandlerSuccess
Short bOBSEInstalled
Begin Menumode 1044
Set bOBSEInstalled to 0
SetStage XjTestExitToMainMenuEventHandlerQuest 10
If bOBSEInstalled == 0
MessageBox "OBSE is not installed"
Return
EndIf
If GetGameRestarted
Set bEventHandlerSuccess to SetEventHandler "ExitToMainMenu" XjTestExitToMainMenuEventHandlerFunctionScript
If bEventHandlerSuccess
MessageBox "ExitToMainMenu: Event handler successfully created"
Else
MessageBox "ExitToMainMenu: Failed to create event handler"
EndIf
EndIf
End
If I run the game with this plugin activated, I only ever see the message "ExitToMainMenu: Event handler successfully created" and I don't see the event handler's message box.
I am using OBSE v21 and it is loaded and working (I don't see the "OBSE is not installed" message box which would appear if something was wrong).
I cannot find an ExitToMainMenu habdler in the code, but there is a MAinMenu handler. Can you try using MainMenu instead?
First, I want to say that OBSE's documentation says that ExitToMainMenu is the event handler to use: http://obse.silverlock.org/obse_command_doc.html#Events
PostLoadGame gameLoadedSuccessfully:bool 0 if error occurred during load (corrupt savegame?), 1 otherwise
ExitGame NONE exiting from main menu or in-game menu
ExitToMainMenu NONE exiting from in-game menu to main menu
QQQ NONE exiting via QQQ/QuitGame console command
OnNewGame NONE user starts a new game from the main menu
https://github.com/llde/Oblivion-Script-Extender/blob/master/obse/obse_command_doc.html (Line 5677)
<tr><td>PostLoadGame</td><td>gameLoadedSuccessfully:bool</td><td>0 if error occurred during load (corrupt savegame?), 1 otherwise</td></tr>
<tr><td>ExitGame</td><td>NONE</td><td>exiting from main menu or in-game menu</td></tr>
<tr><td>ExitToMainMenu</td><td>NONE</td><td>exiting from in-game menu to main menu</td></tr>
<tr><td>QQQ </td><td>NONE</td><td>exiting via QQQ/QuitGame console command</td></tr>
<tr><td>OnNewGame</td><td>NONE</td><td>user starts a new game from the main menu</td></tr>
There is nothing in either of those documents about a MainMenu event handler.
I managed to take the scripts I posted above in my test plugin and modified the one line to this as per your suggestion:
Set bEventHandlerSuccess to SetEventHandler "MainMenu" XjTestExitToMainMenuEventHandlerFunctionScript
Unfortunately, the event handler is still not firing when I expect it to (assuming the MainMenu event handler is identical to what the documentation describes for ExitToMainMenu). Maybe there is a misunderstanding though. My understanding is that the MainMenu (or ExitToMainMenu) event handler is supposed to activate if the player has a game loaded and they then use the "Quit -> Main Menu" buttons (ie. they exit to the main menu). Is this correct? If not, do you know what circumstances are supposed to cause this event handler to activate?
Also, during my testing right now, I've found something I should mention. For the **SetEventHandler ** command, the first parameter is supposed to be the event handler you want to create. I've found that it is possible to add text to that parameter that does not match any of the event handlers that OBSE has defined and the script compiler will not complain. The SetEventHandler command will also set variables to 1 in an expression even though it is being asked to create an event handler that does not exist.
As an example of this, I took my script above and typed Set bEventHandlerSuccess to SetEventHandler "OnLife" XjTestExitToMainMenuEventHandlerFunctionScript
(there is no OnLife event handler). The script compiler didn't complain. I then started the game and saw a message box that said: "OnLife: Event handler successfully created". This means that
Another example is the test plugin I created above. You said that the ExitToMainMenu event handler doesn't exist and yet my script reported that the ExitToMainMenu event handler was successfully created.
I currently see four problems that need to be fixed:
- OBSE's documentation needs to be corrected to remove the reference to the non-existent ExitToMainMenu event handler and add notes for the MainMenu event handler.
- If the MainMenu event handler is supposed to do what I mentioned above, it is currently not working.
- The Construction Set's script compiler is not complaining if I add text to the SetEventHandler command's first parameter that does not correspond a valid event handler.
- The SetEventHandler command is indicating successful event handler creation and, if used in an expression, setting variables to 1 (success) even if the command's first parameter does not correspond to a valid event handler (and presumably fails to create the event handler).
On a semi-related note, I've found in testing that the OnDeath event handler honours the fDyingTimer setting whereas the GetDead script command returns true immediately and ignores that setting. Is this intended behavior? Is so, do you know if there would be any problems with setting fDyingTimer to 0 in my plugin to make my OnDeath event handler activate as soon as the PC dies?
- Correct. Documentation should be fixed. Other docs issue were reported. 2)What's the beheviour you are experiencing with MenuMode? (I still have to understand several bits of the assembly black magic in OBSE). 3-4) OBSE provide an abstraction for user defined events. They are called with a DIspatchEvent call. So this is an intended beheviour. (For my understading of the code. I didn't wrote this) 5)Shouldn't be any problem.However I'd like to have an handler that ignore fDyingTimer.
Probably GetDead simply do a check on the actor state Alive/Dead (which is set after applying the fatal damage or by the kill command) so it will returns true immediately, while OnDeath handler is the actual moment the game realize that actor is now dead (which happens after fDyingTimer).
I'll try give a breakdown of what's happening when I try to use my test plugin with these scripts:
ScriptName XjTestExitToMainMenuEventHandlerFunctionScript
Begin Function {}
MessageBox "MainMenu event has occured."
End
ScriptName XjTestExitToMainMenuEventHandlerQuestScript
Short bEventHandlerSuccess
Short bOBSEInstalled
Begin Menumode 1044
Set bOBSEInstalled to 0
SetStage XjTestExitToMainMenuEventHandlerQuest 10
If bOBSEInstalled == 0
MessageBox "OBSE is not installed"
Return
EndIf
If GetGameRestarted
Set bEventHandlerSuccess to SetEventHandler "MainMenu" XjTestExitToMainMenuEventHandlerFunctionScript
If bEventHandlerSuccess != 1
MessageBox "MainMenu: Failed to create event handler"
Else
MessageBox "MainMenu: Event handler successfully created"
EndIf
EndIf
End
You can download my updated test plugin here if you want to test this issue yourself: https://github.com/XJDHDR/xjdhdr-random-code/blob/master/Random%20stuff%20uploaded%20for%20sharing%20online/MainMenu%20Event%20Handler%20test.esp?raw=true
Steps to reproduce:
- Install my test plugin and activate it in your load order.
- Start Oblivion with OBSE loaded.
- Once at the main menu, wait for a message box to appear that says "MainMenu: Event handler successfully created".
- Load a game or start a new game.
- Open the pause menu and choose to exit to main menu.
Expected result:
- A message box that says "MainMenu event has occured." appears.
Actual result:
- No message box appears.