Jump to content

[LE] Help with Menu with sub-options


Recommended Posts

Good morning - I've been working on a message box menu with sub options/categories. It half works but I am running into a few specific problems.

First is I have to click buttons twice for them to register. The other bigger problem is I can only go through part of the menu before it closes itself. It doesn't matter which order I go through the menu, it only allows me to make one selection before it closes itself entirely.

Here is the code.. and Thanks in advance..
(the goal is to have a menu that works similar to the one seen in Campfire mod)

Event Oninit()
	Game.DisablePlayerControls(False, False, False, False, False, True) ; Momentarily disable other menus
	Utility.Wait(0.01) ; This ensures equipping the token from the favorites menu works
	Game.EnablePlayerControls(False, False, False, False, False, True) ; Undo DisablePlayerControls
		Menu()
endEvent

Function Menu(Bool abMenu = True, Int aiButton = 0)
	While abMenu
		If aiButton != -1					; Wait for input (this can prevent problems if recycling the aiButton argument in submenus)
			aiButton = myMenu000.Show()	                ; Main Menu
			abMenu = False					; End the function

			If aiButton == 0				; OPTION 1 - Message Menu
				debug.notification("self start mod")	; OPTION 1a - Default (closes menu)
				aiButton = myMenu004.Show()

			ElseIf aiButton == 1				; OPTION 2 - Custom Menu
				aiButton = myMenu004.Show()
				If aiButton == -1
				ElseIf aiButton == 0			; OPTION 2a - Location Options
					aiButton = myMenu001.Show()
					If aiButton == -1
					ElseIf aiButton == 0		; OPTION 2a1 - All Locations
						aiButton = myMenu004.Show()
						debug.notification("All Locations")
						startall()
					ElseIf aiButton == 1		; OPTION 2a2 - Capitols Only
						aiButton = myMenu004.Show()
						debug.notification("Capitols Only")
						startCap()
					ElseIf aiButton == 2		; OPTION 2a3 - Back
						aiButton = myMenu004.Show()
					EndIf
			
				ElseIf aiButton == 1			; OPTION2b - Merchant Options
					aiButton = myMenu002.Show()
					If aiButton == -1
					ElseIf aiButton == 0		; OPTION 2b1 - ON
						aiButton = myMenu004.Show()
						debug.notification("Marketplace Open")
						startMarket()
					ElseIf aiButton == 1		; OPTION 2b2 - OFF
						aiButton = myMenu004.Show()
						debug.notification("Marketplace Closed")
						endMarket()
					ElseIf aiButton == 2		; OPTION 2b3 - Back
						aiButton = myMenu004.Show()
					EndIf

				ElseIf aiButton == 2			; OPTION2c - College Options
					aiButton = myMenu003.Show()
					If aiButton == -1
					ElseIf aiButton == 0		; OPTION 2c1 - ON
						aiButton = myMenu004.Show()	
						debug.notification("College Open")
						startcollege()
					ElseIf aiButton == 1		; OPTION 2c2 - OFF
						aiButton = myMenu004.Show()
						debug.notification("College Closed")
						endcollege()
					ElseIf aiButton == 2		; OPTION 2c3 - Back
						aiButton = myMenu004.Show()
					EndIf

				ElseIf aiButton == 3			; OPTION2d - DONE
					debug.notification("Please Wait")
					myFadeOut.apply()
				EndIf
			EndIf
		EndIf
	EndWhile
EndFunction
Edited by javaplaza
Link to comment
Share on other sites

For Menu's with sub menu's, I prefer to use separate functions for each menu, that way it's easier to specify which menu opens and when. Here's an example script:

 

 

 

Message Property Message1 Auto 
Message Property Message2 Auto 
Message Property Message3 Auto 

Event SomeEvent()
    Menu1() ;open main menu
EndEvent 

Function Menu1()
    Int Button = Message1.Show()
    
    If Button == 0
        ;do something and close the menu system
    Elseif Button == 1
        ;Do something 
        Menu1() ;Re-Open the main menu
    Elseif Button == 2
        ;optionally do something
        Menu2() ;open menu 2
    Endif 
EndFunction 

Function Menu2()
    Int Button = Message2.Show()
    
    If Button == 0
        ;do something and close the menu system
    Elseif Button == 1
        ;optionally do something
        Menu3() ;open menu 3 
    Elseif Button == 2
        ;optionally do something
        Menu1() ;go back to main menu
    Endif 
EndFunction 


Function Menu3()
    Int Button = Message3.Show()
    
    If Button == 0
        ;do something and close the menu system
    Elseif Button == 1
        ;optionally do something
        Menu2() ;go back to menu 2
    Elseif Button == 2
        ;optionally do something
        Menu1() ;go back to main menu
    Endif 
EndFunction 

Edited by dylbill
Link to comment
Share on other sites

let me look over this but thank you so much for replying !

some had suggested using states in this same way but im still struggling to get that to compile. im going to fiddle with your code for a little while and fill in the blanks. it looks like exactly what i was trying to do! tyvm

 

edit: the notes you provided really help

Edited by javaplaza
Link to comment
Share on other sites

- Remove the "While" loop.


- This line is unnecessary.

If aiButton != -1 ; Wait for input (this can prevent problems if recycling the aiButton argument in submenus)


- Make each "Menu Option" on it's own "IF" statement.

Custom Menu

Merchant Options

College Options


- Menu buttons works in order of 0, 1, 2, 3,... etc till 9, so -1 does not work in menu buttons.


- Sub Menus & Sub Sub Menus & Sub Sub Sub Menus works better if they are all call from inside "Functions", calling Functions within Functions, this help for keeping track of what you are doing.



EDIT: dylbill post the same thing while i was writing...

Edited by maxarturo
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...