Talk:QuitToMainMenu - Game

From the CreationKit Wiki
Jump to navigation Jump to search

This function doesn't immediately terminate the calling Papyrus stack or any others: your code will keep executing while the game fades out to the main menu. Papyrus call stacks are cleaned up when the player resumes gameplay (i.e. by loading a save or starting a new playthrough), but calls are not; when these calls return, Papyrus errors will note that a call returned to a call stack ID that no longer exists.

Most game state is cleaned up either when the main menu is reached, or when the player resumes gameplay (i.e. by loading a save or starting a new playthrough). However, some things "bleed through." Open Message boxes will get stuck in the background of the main menu, and will only be operable after gameplay resumes; when the player dismisses the message, the relevant Show call will return, logging the error described above.

Even more strangely, it seems that Papyrus call stacks are not cleaned up when the main menu is reached. In fact, they re-execute from the very beginning, even if the events that originally triggered them should now be impossible. It seems that the sequence of events that occurs here is:

  • Papyrus call stacks occur and trigger QuitToMainMenu.
  • The game fades to the main menu, continuing to execute Papyrus code.
  • The game reaches the main menu.
    • All quest aliases are cleared.
    • The player's parent cell and parent worldspace are both set to None.
    • All running Papyrus call stacks are re-executed from the beginning.
  • The player loads a save.
    • All running Papyrus call stacks are terminated immediately. However, Skyrim does not terminate any latent function calls that are still running; these calls "bleed through."
    • Papyrus stacks are restored from the savegame as appropriate.
  • Any latent calls that have "bled through" will return, logging Papyrus errors if their call stack IDs are now unused.
    • (What happens if the savegame has a different call stack with the same ID number?)

My experience with this phenomenon occurs with a SkyUI MCM. This stripped-down sample script should trigger the same phenomena, though:

   Scriptname TestPlayerAlias extends ReferenceAlias
   
   Message Property MyMessage Auto
   
   Event OnPlayerLoadGame()
      Debug.Trace("\n\nReceived OnPlayerLoadGame\n\n")
      ObjectReference PlayerRef = Game.GetPlayer()
      If PlayerRef && (PlayerRef.GetParentCell() || PlayerRef.GetWorldSpace())
         MyMessage.Show()
         Game.QuitToMainMenu()
      Else
         Debug.MessageBox("We received OnPlayerLoadGame while in the main menu!")
      EndIf
   EndEvent

One would load a savegame with this script on a player alias, and then dismiss the message box. After returning to the main menu, the Papyrus log should show two "Received OnPlayerLoadGame" lines. DavidJCobb (talk) 2017-04-04T02:43:54 (EDT)

I always had a strange feeling about quitting to the main menu, even through the journal menu, so I always just quit to desktop. --Lisselli (talk) 2017-04-04T11:40:39 (EDT)