Difference between revisions of "Options Menu"
Jump to navigation
Jump to search
→Examples
imported>Threedee m (→Examples) |
imported>Threedee |
||
Line 24: | Line 24: | ||
EndEvent</source> | EndEvent</source> | ||
*For the next example, we'll offer sub-options for each main selection. For a multilevel menu, | *For the next example, we'll offer sub-options for each main selection. For a multilevel menu, functions can be used to keep the menu well organized. Keep in mind that you can assign conditions to each button in the Message forms, 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. | ||
<source lang="papyrus">ScriptName OptionsMenuScript extends ObjectReference | <source lang="papyrus"> | ||
ScriptName OptionsMenuScript extends ObjectReference | |||
;=================================================== | |||
ObjectReference Property MenuBook Auto | |||
Message Property MainMenuMESG Auto | Message Property MainMenuMESG Auto | ||
Message Property BreakfastMESG Auto | Message Property BreakfastMESG Auto | ||
Message Property LunchMESG Auto | Message Property LunchMESG Auto | ||
Message Property DinnerMESG Auto | Message Property DinnerMESG Auto | ||
;=================================================== | |||
Event OnRead() | Event OnRead() | ||
Game.DisablePlayerControls(False, False, False, False, False, True) ; | Game.DisablePlayerControls(False, False, False, False, False, True) ; Temporarily disable other menus | ||
Menu() | Menu() | ||
Game.EnablePlayerControls(False, False, False, False, False, True) ; | Game.EnablePlayerControls(False, False, False, False, False, True) ; Re-enable Player controls | ||
EndEvent | EndEvent | ||
;=================================================== | |||
Function Menu() | |||
int aiButton = MainMenuMESG.Show() ; Main Menu | |||
If aiButton == 0 ; Breakfast | |||
BreakfastMenu() | |||
ElseIf aiButton == 1 ; Lunch | |||
LunchMenu() | |||
ElseIf aiButton == 2 ; Dinner | |||
DinnerMenu() | |||
ElseIf aiButton == 3 ; Quit the menu | |||
Return | |||
EndIf | |||
EndFunction | |||
;=================================================== | |||
Function BreakfastMenu() | |||
int aiButton = BreakfastMESG.Show() | |||
If aiButton == 0 | |||
Debug.Notification("Choice = Sweet Roll & Coffee") | |||
ElseIf aiButton == 1 | |||
Debug.Notification("Choice = Pancakes, Bacon & Eggs") | |||
ElseIf aiButton == 2 | |||
Debug.Notification("Choice = Chicken Fried Pony Steak") | |||
ElseIf aiButton == 3 ; Return to the main menu | |||
Return | |||
EndIf | |||
EndFunction | |||
;=================================================== | |||
Function LunchMenu() | |||
int aiButton = LunchMESG.Show() | |||
If aiButton == 0 | |||
Debug.Notification("Choice = Glazed Turkey Sandwich") | |||
ElseIf aiButton == 1 | |||
Debug.Notification("Choice = Grilled Ham Sandwich") | |||
ElseIf aiButton == 2 | |||
Debug.Notification("Choice = Shredded Pony Sandwich") | |||
ElseIf aiButton == 3 ; Return to the main menu | |||
Return | |||
EndIf | |||
EndFunction | |||
;=================================================== | |||
Function DinnerMenu() | |||
aiButton = DinnerMESG.Show() | |||
If aiButton == 0 | |||
Debug.Notification("Choice = Filet Mignon") | |||
ElseIf aiButton == 1 | |||
Debug.Notification("Choice = Pony Fajitas") | |||
ElseIf aiButton == 2 | |||
Debug.Notification("Choice = Lobster") | |||
ElseIf aiButton == 3 ; Return to the main menu | |||
Return | |||
EndIf | |||
EndFunction | |||
;=================================================== | |||
</source> | |||
*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 |