Difference between revisions of "Options Menu"
Jump to navigation
Jump to search
m
Put new example/notes back in.
imported>JustinOther m (Reverted edits by Threedee (talk) to last revision by JustinOther) |
imported>JustinOther m (Put new example/notes back in.) |
||
Line 2: | Line 2: | ||
Using [[Show - Message]], it is possible to make an options menu with any number of buttons and/or levels. This is enabling as one can maintain but a single plugin with an options menu offering multiple configuration setting rather than necessitating multiple versions. In these examples, we'll use apparel items and a book, but a menu can be prompted and managed in a number of ways. First, create a message(s) form(s) and add/fill the buttons with the options you'd like to offer. Note that no more than ten buttons can be in a message box and that the button indices are offset by one such that the first option's index is 0 and not 1. If offering a lot of options, it's best to think ahead regarding how you want to organize your options, making the message forms first, then plugging them into the script. | Using [[Show - Message]], it is possible to make an options menu with any number of buttons and/or levels. This is enabling as one can maintain but a single plugin with an options menu offering multiple configuration setting rather than necessitating multiple versions. In these examples, we'll use apparel items and a book, but a menu can be prompted and managed in a number of ways. First, create a message(s) form(s) and add/fill the buttons with the options you'd like to offer. Note that no more than ten buttons can be in a message box and that the button indices are offset by one such that the first option's index is 0 and not 1. If offering a lot of options, it's best to think ahead regarding how you want to organize your options, making the message forms first, then plugging them into the script. | ||
== Examples == | === Examples === | ||
== Single Level Menu == | |||
*For the first example, we'll have only three options: "Mage", "Thief", and "Warrior". The token should be unplayable in this case. When the item is added to the player, the menu will be prompted and will exit as soon as a button is selected, executing the appropriate code right after the token is silently removed. | *For the first example, we'll have only three options: "Mage", "Thief", and "Warrior". The token should be unplayable in this case. When the item is added to the player, the menu will be prompted and will exit as soon as a button is selected, executing the appropriate code right after the token is silently removed. | ||
Line 14: | Line 15: | ||
If akNewContainer == PlayerREF ; Only the player | If akNewContainer == PlayerREF ; Only the player | ||
Int iButton = OptionsMESG.Show() ; Shows your menu. | Int iButton = OptionsMESG.Show() ; Shows your menu. | ||
PlayerREF.RemoveItem(MenuARMO, 1, True) ; Silently remove token | PlayerREF.RemoveItem(MenuARMO, 1, True) ; Silently remove token. 'Self' does not work in this context, thus the property | ||
If iButton == 0 ; Mage | If iButton == 0 ; Mage | ||
Debug.Notification("Mage selected") | Debug.Notification("Mage selected") | ||
Line 24: | Line 25: | ||
EndIf | EndIf | ||
EndEvent</source> | EndEvent</source> | ||
== Menu with sub-options == | |||
*For | *For this example, we'll offer sub-options for each main selection. For a multilevel menu, a function works well. Keep in mind each button can have conditions, so you could hide "Lunch" and "Dinner" if it's time for breakfast or hide "Lobster" if it's not currently available. In this case, to make it repeatable, we'll use a book so the menu will show each time it is read. A book cannot be favorited or hotkeyed, unlike an apparel item. A potion can be hotkeyed, but it will be consumed when used and not remain hotkeyed even if immediately replaced. This example will let the user choose breakfast, lunch, or dinner, then close after one meal is selected. As your options become fleshed out, keep in mind that you can add and use arguments to store information temporarily rather than necessitating declarations of more variables or properties. | ||
<source lang="papyrus">ScriptName OptionsMenuScript extends ObjectReference | <source lang="papyrus">ScriptName OptionsMenuScript extends ObjectReference | ||
Line 68: | Line 69: | ||
EndWhile | EndWhile | ||
EndFunction</source> | EndFunction</source> | ||
== Multilevel, looping menu == | |||
*To make a multilevel, looping menu with thirty buttons that will not close until a "Done" button is pressed, use the above method but with an altered Menu() function. Note that you can jump to a given message by specifying the aiMessage argument when calling the function. Sub-options as described in the previous example can be added to the below in the same manner. Theoretically, any number of options can be added with the below structure. | *To make a multilevel, looping menu with thirty buttons that will not close until a "Done" button is pressed, use the above method but with an altered Menu() function. Note that you can jump to a given message by specifying the aiMessage argument when calling the function. Sub-options as described in the previous example can be added to the below in the same manner. Theoretically, any number of options can be added with the below structure. | ||
<source lang="papyrus">ScriptName OptionsMenuScript extends ObjectReference | <source lang="papyrus">ScriptName OptionsMenuScript extends ObjectReference | ||
Line 141: | Line 143: | ||
EndFunction</source> | EndFunction</source> | ||
== Notes == | === Notes === | ||
*Given the buttons in Skyrim are listed from side to side, it is easy to spill over the edges of the user's monitor, particularly if it's a 4:3, in the event either the options are too verbose or there are too many options presented by a single message form. Currently, there's no way to list them from top to bottom as they were in previous Bethesda games. To mitigate this, keep the button text to a minimum and/or make sure to always set up conditions on mutually exclusive buttons to ensure only applicable options are presented. | *Given the buttons in Skyrim are listed from side to side, it is easy to spill over the edges of the user's monitor, particularly if it's a 4:3, in the event either the options are too verbose or there are too many options presented by a single message form. Currently, there's no way to list them from top to bottom as they were in previous Bethesda games. To mitigate this, keep the button text to a minimum and/or make sure to always set up conditions on mutually exclusive buttons to ensure only applicable options are presented. | ||
*To conditionalize buttons | *To conditionalize buttons using variables declared in your script/quest, use [[GetVMScriptVariable]] and [[GetVMQuestVariable]]. | ||
*To hide buttons you wish to fill in later, add an impossible condition like 'IsXBox == -1'. | *To hide buttons you wish to fill in later, add an impossible condition like 'IsXBox == -1'. | ||
* Conditionalizing MessageBox buttons will not change their indices such that, for instance, button 9 will still execute the "Done" code in the last example even if buttons 0-8 are hidden. | *For debugging purposes, you could configure hidden menu buttons (in the Message forms) that only show when you set a GlobalVariable flag. For instance, create a GlobalVariable called "myDebugFlag" in the CK. Set a condition on one of your menu buttons to be "GetGlobalValue myDebugFlag == 1". In your script, have that button activate your debugging function. Now if you set myGlobalValue to 1 in the CK your button will appear in the menu. Before releasing the mod, remember to set myDebugFlag to 0 to keep the button hidden. | ||
* To learn how to assign user-created messageboxes as values to the message box | *Conditionalizing MessageBox buttons will not change their indices such that, for instance, button 9 will still execute the "Done" code in the second last example even if buttons 0-8 are hidden. | ||
*If the Message | *To learn how to assign user-created messageboxes as values to the message box Properties defined in the above scripts, see [[Bethesda_Tutorial_Papyrus_Introduction_to_Properties_and_Functions#Hooking_up_the_message_boxes_to_the_properties_in_the_script|the Papyrus tutorial's page on Properties and Functions]] | ||
*If the Message is a Notification (without buttons) instead of a Message Box the Show() will return a -1. | *If the Message Property isn't filled in the CK the Show() will always return a 0, '''and the Message will not be shown'''. | ||
== See Also == | *If the Message is a Notification (without buttons) instead of a Message Box the Show() will return a -1, '''in which case you will never be presented with an options menu'''. | ||
=== See Also === | |||
[[Show - Message]] | [[Show - Message]] | ||
[[Category:Scripting]] | [[Category:Scripting]] | ||
[[Category:Papyrus]] | [[Category:Papyrus]] | ||
[[Category:Papyrus_Tutorials]] | [[Category:Papyrus_Tutorials]] | ||
[[Category:Tutorials]] | [[Category:Tutorials]] |