Options Menu

From the CreationKit Wiki
Revision as of 14:01, 12 April 2012 by imported>JustinOther (Initial)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Overview

Using Show - Message, it is possible to make an options menu with any number of buttons and/or levels. In this example, we'll use an unplayable armor token, but a menu can be prompted and managed in a number of ways. First off, create a message form and add/fill in its buttons. Note that no more than ten buttons can be offered by any given message box and that the button indices are offset by one such that the first option's index is 0 and not 1.

Examples

  • For the first example, we'll have only three options: Mage, Thief, and Warrior. Each time the item is equipped by the player, the menu will be prompted and will exit as soon as a button is selected, executing the appropriate code.
ScriptName OptionsMenuScript extends ObjectReference

Message Property OptionsMESG Auto

Event OnEquipped(Actor akActor)

	If akActor == Game.GetPlayer() ; Only the player
		Game.DisablePlayerControls(False, False, False, False, False, True) ; Momentarily disable other menus
		akActor.EquipItem(GetBaseObject(), True, True) ; Prevent unequip/reequip in favorites until the current menu is resolved
		Utility.Wait(0.01) ; This ensures equipping the token from the favorites menu works
		akActor.UnequipItem(GetBaseObject(), True, True) ; Silently unequip item
		Game.EnablePlayerControls(False, False, False, False, False, True) ; Undo DisablePlayerControls
		Int iButton = OptionsMESG.Show() ; Shows your menu. iButton == -1 until input
		If (iButton == 0) ; Mage
			Debug.Notification("Mage selected")
		ElseIf (iButton == 1) ; Thief
			Debug.Notification("Thief selected")
		ElseIf (iButton == 2) ; Warrior
			Debug.Notification("Warrior selected")
		EndIf
	EndIf
	
EndEvent
  • For the next example, we'll offer sub-options for each main selection. For a multilevel menu, a function works well. Keep in mind each message forms' buttons 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.
ScriptName OptionsMenuScript extends ObjectReference

Message Property MainMenuMESG Auto
Message Property BreakfastMESG Auto
Message Property LunchMESG Auto
Message Property DinnerMESG Auto

Event OnEquipped(Actor akActor)

	If akActor == Game.GetPlayer()
		Game.DisablePlayerControls(False, False, False, False, False, True)
		akActor.EquipItem(GetBaseObject(), True, True)
		Utility.Wait(0.01)
		akActor.UnequipItem(GetBaseObject(), True, True)
		Game.EnablePlayerControls(False, False, False, False, False, True)
		Menu()
	EndIf
	
EndEvent 

Function Menu(Bool abMenu = True, Int aiButton = 0)

	While abMenu
		If (aiButton != -1) ; Wait for input
			aiButton = MainMenuMESG.Show() ; Main Menu
			If (aiButton == 0) ; Breakfast
				aiButton = BreakfastMESG.Show()
				abMenu = False
				If (aiButton == 0) ; Sweet Roll
				ElseIf (aiButton == 1) ; Pancakes
				ElseIf (aiButton == 2) ; Bacon & Eggs
				EndIf
			ElseIf (aiButton == 1) ; Lunch
				aiButton = LunchMESG.Show()
				abMenu = False
				If (aiButton == 0) ; Turkey Sandwich
				ElseIf (aiButton == 1) ; Ham Sandwich
				ElseIf (aiButton == 2) ; BLT
				EndIf
			ElseIf (aiButton == 2) ; Dinner
				aiButton = DinnerMESG.Show()
				abMenu = False
				If (aiButton == 0) ; Filet Mignon
				ElseIf (aiButton == 1) ; Lobster
				ElseIf (aiButton == 2) ; Fried Chicken
				EndIf
			EndIf
		EndIf
	EndWhile

EndFunction

See Also

Show - Message