Difference between revisions of "MessageBox Tutorial/Ensuring Your Menu Is Seen"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Haama
(Added Generalization disclaimer)
imported>Haama
(Better Basics)
Line 5: Line 5:
For this tutorial, you will want to [[MessageBox_Tutorial:_Centralized_Decision_Catching|centralize your decision catching]].
For this tutorial, you will want to [[MessageBox_Tutorial:_Centralized_Decision_Catching|centralize your decision catching]].


----


If another menu is shown before the player makes a decision, that other menu will overwrite your menu (the player will see the other menu), and any decision the player makes will be limited to that other menu. This leads to a few problems:
If another menu is shown before the player makes a decision, that other menu will overwrite your menu (the player will see the other menu), and any decision the player makes will be limited to that other menu. This leads to a few problems:
Line 17: Line 18:
*Again, the player won't see or be able to answer your menus
*Again, the player won't see or be able to answer your menus


To make sure your menu is read, after the player has finished with the other menu system so you won't disturb it's processing, replace: (due to wiki limitations, the large '''''if''''' test has been given line breaks, whereas in the CS it would all be on one line
To make sure your menu is read a timer will start counting down when the (yours or another mod's) menu closes. If the player responded to your menu, the '''''Choice''''' will be updated (> -1). If the player responded to another menu, '''''Choice''''' won't be updated and the timer will run down. Once the timer reaches 0, your menu will be displayed again. This also gives the other mod's menus a chance to finish up, as any new menu will restart the timer.
 
To do all this, replace:
<pre>  Elseif (Choosing > 0) && (Choice == -1) ;No choice yet
<pre>  Elseif (Choosing > 0) && (Choice == -1) ;No choice yet
     Set Choice to GetButtonPressed
     Set Choice to GetButtonPressed
     Return</pre>
     Return</pre>
with
with (due to wiki limitations, the large '''''if''''' test has been given line breaks, whereas in the CS it would all be on one line)
<pre>float MessageTimer
<pre>float MessageTimer
short MessageButton
short MessageButton
Line 65: Line 68:
     Return</pre>
     Return</pre>


And now I'm sure you want to know what all of that actually does, but some quick background first. When another menu overwrites yours, any response the player makes will be caught by the other script's [[GetButtonPressed]], but not by your script's [[GetButtonPressed]]. That means '''''Choice''''' will always be '''''-1'''''. So, these extra lines will start a countdown once the player has left the menu screen ([[MenuMode]] 1001). If both 1 second and 45 frames pass and [[GetButtonPressed]] is still returning '''''-1''''' then your menu is reset (with <u>'''''set Choosing to -(Choosing)'''''</u>. The countdown won't run when the player presses <ESC> and looks through their options (that's what that whole mess of <u>'''''if (MenuMode 1004)'''''</u>... is for). This won't disturb other menus, because the countdown is reset whenever a new menu is displayed. So, once the other mod's menus are out of the way, your menu will be shown again.
And now I'm sure you want to know the details of what all that actually does. When another menu overwrites yours, any response the player makes will be caught by the other script's [[GetButtonPressed]], but not by your script's [[GetButtonPressed]]. That means '''''Choice''''' will always be '''''-1'''''. So, these extra lines will start a countdown once the player has left the menu screen ([[MenuMode]] 1001). If both 1 second and 45 frames pass and [[GetButtonPressed]] is still returning '''''-1''''' then your menu is reset (with <u>'''''set Choosing to -(Choosing)'''''</u>. The countdown won't run when the player presses <ESC> and looks through their options (that's what that whole mess of <u>'''''if (MenuMode 1004)'''''</u>... is for). This won't disturb other menus, because the countdown is reset whenever a new menu is displayed. So, once the other mod's menus are out of the way, your menu will be shown again.




[[Category: Scripting Tutorials]]
[[Category: Scripting Tutorials]]

Revision as of 13:52, 30 June 2007

This is a subsection of the MessageBox Tutorial, and uses this script as a base. The following code may or may not require certain aspects of that script to work, however the information should prove useful for any script (it will take a bit of care to make it work, though).


For this tutorial, you will want to centralize your decision catching.


If another menu is shown before the player makes a decision, that other menu will overwrite your menu (the player will see the other menu), and any decision the player makes will be limited to that other menu. This leads to a few problems:

  • Your script will continue to run, once a frame, at least these lines:
  if (Choosing == 0)
...
  Elseif (Choosing > 0) && (Choice == -1) ;No choice yet
    Set Choice to GetButtonPressed
    Return

until the menu is started up again (activated again).

  • Your script won't run through the exit if (Choosing == 0)
  • Again, the player won't see or be able to answer your menus

To make sure your menu is read a timer will start counting down when the (yours or another mod's) menu closes. If the player responded to your menu, the Choice will be updated (> -1). If the player responded to another menu, Choice won't be updated and the timer will run down. Once the timer reaches 0, your menu will be displayed again. This also gives the other mod's menus a chance to finish up, as any new menu will restart the timer.

To do all this, replace:

  Elseif (Choosing > 0) && (Choice == -1) ;No choice yet
    Set Choice to GetButtonPressed
    Return

with (due to wiki limitations, the large if test has been given line breaks, whereas in the CS it would all be on one line)

float MessageTimer
short MessageButton
...
  Elseif (Choosing > 0) && (Choice == -1) ;No choice yet
    if (MessageTimer > 0) || (MessageCounter > 0)
      set Choice to GetButtonPressed
      if (Choice > -1)
        return
      endif
      if (MenuMode 1001 == 0)
        if (MenuMode 1004) || (MenuMode 1005) || (MenuMode 1006) ||
           (MenuMode 1010) || (MenuMode 1011) || (MenuMode 1013) ||
           (MenuMode 1015) || (MenuMode 1016) || (MenuMode 1017) ||
           (MenuMode 1018) || (MenuMode 1019) || (MenuMode 1020) ||
           (MenuMode 1021) || (MenuMode 1024) || (MenuMode 1038) ||
           (MenuMode 1039) || (MenuMode 1044) || (MenuMode 1045) ||
           (MenuMode 1046) || (MenuMode 1047) || (MenuMode 1057)
          return
        else
          set MessageTimer to (MessageTimer - GetSecondsPassed)
          set MessageCounter to (MessageCounter - 1)
          return
        endif
      else ;MenuMode 1001
        set MessageTimer to 1
        set MessageCounter to 45
        return
      endif
    else ;Display menu again
      message "Trying menu again..."
      set Choosing to -(Choosing)
      return
    endif

and whenever you display a menu, setup the MessageTimer to 1 and the MessageCounter to 45, as such:

  Elseif (Choosing == -1) ;Display your menu
    Messagebox "Would you like to donate gold or food?" "Gold" "Food"
                                                        "Blood" "Cancel"
    Set Choosing to 1
    Set Choice to GetButtonPressed
    Set MessageTimer to 1
    Set MessageCounter to 45
    Return

And now I'm sure you want to know the details of what all that actually does. When another menu overwrites yours, any response the player makes will be caught by the other script's GetButtonPressed, but not by your script's GetButtonPressed. That means Choice will always be -1. So, these extra lines will start a countdown once the player has left the menu screen (MenuMode 1001). If both 1 second and 45 frames pass and GetButtonPressed is still returning -1 then your menu is reset (with set Choosing to -(Choosing). The countdown won't run when the player presses <ESC> and looks through their options (that's what that whole mess of if (MenuMode 1004)... is for). This won't disturb other menus, because the countdown is reset whenever a new menu is displayed. So, once the other mod's menus are out of the way, your menu will be shown again.