Trouble With Menus

Post » Tue May 17, 2011 9:56 am

Here is a snippet of code I wrote for a menu. When I play the mod in game I get the Main Menu and all the options, but no matter which option(s) I choose I never get to other messages/menulevels. It just stays at the main menu and after three selections it exits, I don't even have to hit the Exit button. The whole thing is almost 600 lines and I've looked over it all and must be missing something major. I'm assuming that the error lies in the code for the main menu so thats mostly what I have here. If anyone see any glaring error please let me know.


Begin OnEquip Player	showmessage SWULMainMenuendBegin menumode	showmessage SWULMainMenu	if SWMenuLevel == 0		set SWMenuButton to GetButtonPressed		if SWMenuButton == -1			return		elseif SWMenuButton == 0			if SWULOffOnAmmo == 0				showmessage SWULAmmoMenuOff				set SWMenuLevel to 10			elseif SWULOffOnAmmo == 1				showmessage SWULAmmoMenuOn SWULPPLAmmo				set SWMenuLevel to 20			endif		elseif SWMenuButton == 1			if SWULOffOnDrink == 0				showmessage SWULDrinkMenuOff				set SWMenuLevel to 11			elseif SWULOffOnDrink == 1				showmessage SWULDrinkMenuOn SWULPPLDrink				set SWMenuLevel to 21			endif		elseif SWMenuButton == 2			if SWULOffOnUXO == 0				showmessage SWULUXOMenuOff				set SWMenuLevel to 12			elseif SWULOffOnUXO == 1				showmessage SWULUXOMenuOn SWULPPLUXO				set SWMenuLevel to 22			endif		elseif SWMenuButton == 3			if SWULOffOnGrub == 0				showmessage SWULGrubMenuOff				set SWMenuLevel to 13			elseif SWULOffOnGrub == 1				showmessage SWULGrubMenuOn SWULPPLGrub				set SWMenuLevel to 23			endif		elseif SWMenuButton == 4			showmessage SWULGunOptionsMenu			set SWMenuLevel to 34		elseif SWMenuButton == 5			if SWULOffOnMeds == 0				showmessage SWULMedsMenuOff				set SWMenuLevel to 15			elseif SWULOffOnMeds == 1				showmessage SWULMedsMenuOn SWULPPLMeds				set SWMenuLevel to 25			endif		elseif SWMenuButton == 6			showmessage SWULCQCOptionsMenu			set SWMenuLevel to 36		elseif SWMenuButton == 7			Unequipitem SavageWastelandMenuItem 0 1		endif	elseif SWMenulevel == 10 ;This Feature is off do you want to turn it on		set SWMenuButton to GetButtonPressed		if SWMenuButton == -1			return		elseif SWMenuButton == 0 ;Yes			showmessage SWULAmmoMenuOn SWULPPLAmmo 			set SWMenuLevel to 20		elseif SWMenuButton == 1 ;No			showmessage SWULMainMenu			set SWMenuLevel to 0		endif	elseif SWMenulevel == 11		set SWMenuButton to GetButtonPressed		if SWMenuButton == -1			return		elseif SWMenuButton == 0			showmessage SWULDrinkMenuOn SWULPPLDrink			set SWMenuLevel to 21		elseif SWMenuButton == 1			showmessage SWULMainMenu			set SWMenuLevel to 0		endif...

User avatar
Suzy Santana
 
Posts: 3572
Joined: Fri Aug 10, 2007 12:02 am

Post » Tue May 17, 2011 11:16 am

Its because you have this running every single FPS cycle while in any menu.

Begin menumode	showmessage SWULMainMenu


You should have that somewhere that is controled by a variable that will only display it when its actually needed.
User avatar
David John Hunter
 
Posts: 3376
Joined: Sun May 13, 2007 8:24 am

Post » Tue May 17, 2011 9:27 am

Thanks WillieSea, I actually saw that and thought that might be it, but every time I changed anything in that part of the script the menu stopped popping up at all. I guess I need to re-read everything on menus and see what else I'm missing.
User avatar
JD FROM HELL
 
Posts: 3473
Joined: Thu Aug 24, 2006 1:54 am

Post » Tue May 17, 2011 12:16 pm

You probably just need to do something like this:

Begin menumode	if SWMenuLevel == 0		showmessage SWULMainMenu		set SWMenuLevel to 1	elseif SWMenuLevel == 1		set SWMenuButton to GetButtonPressed...

...and of course update all your other "set SWMenuLevel" statements appropriately.
User avatar
Russell Davies
 
Posts: 3429
Joined: Wed Nov 07, 2007 5:01 am

Post » Tue May 17, 2011 2:34 am

Not sure of the context with which the object gets equipped, but having the same showmessage duplicated in both OnEquip and in the start of MessagMode will call it twice when equipped.
Not only that, but the 2 lines after it could be an issue as well
	if SWMenuLevel == 0		set SWMenuButton to GetButtonPressed

Using a variable condition of "== 0" to exclude a function from running every frame can cause issues because 0 is the default value (at load, reload, or first encounter). It could potentially run anytime you access ANY menumode..
Edit: Yeah, what HugePinball says.. or..
Begin OnEquip Player    showmessage SWULMainMenu    set SWMenuLevel to 1endBegin menumode	if SWMenuLevel == 1		set SWMenuButton to GetButtonPressed

User avatar
Robert Jackson
 
Posts: 3385
Joined: Tue Nov 20, 2007 12:39 am

Post » Tue May 17, 2011 4:49 am

Thanks everybody. I've adjusted the script to

Begin menumode	if SWMenuLevel == 0		showmessage SWULMainMenu		set SWMenuLevel to 1	elseif SWMenuLevel == 1		set SWMenuButton to GetButtonPressed		if SWMenuButton == -1			return		elseif SWMenuButton == 0			if SWULOffOnAmmo == 0				showmessage SWULAmmoMenuOff				set SWMenuLevel to 10			elseif SWULOffOnAmmo == 1				showmessage SWULAmmoMenuOn SWULPPLAmmo				set SWMenuLevel to 20			endif		...


But it just exits the menu no matter which option I choose.
User avatar
Elizabeth Davis
 
Posts: 3406
Joined: Sat Aug 18, 2007 10:30 am

Post » Tue May 17, 2011 1:49 am

If you're equipping the object just for the menus, and when done you're unequipping it, do what I suggested before...
Begin OnEquip Player    showmessage SWULMainMenu    set SWMenuLevel to 1endBegin menumode	if SWMenuLevel == 1		set SWMenuButton to GetButtonPressed		if SWMenuButton == -1			return		elseif SWMenuButton == 0                      ...                      ...		elseif SWMenuButton == 7                            set SWMenuLevel to 0			Unequipitem SavageWastelandMenuItem 0 1		endif

User avatar
Emzy Baby!
 
Posts: 3416
Joined: Wed Oct 18, 2006 5:02 pm

Post » Tue May 17, 2011 1:24 am

I've been using the below template which always works for me while remaining easy to add more buttons/menus to ad absurdum, at least until you hit the character count max...
Spoiler
scn InfinimenuObjectSCPTFloat fTimerInt iButtonInt iMessageBoxBegin OnEquip Player	If MenuMode		Set fTimer to 0.5 ; Let Pipboy close before displaying messagebox	EndIf	Player.UnequipItem MenuARMO 0 1 ; Silently unequip item	DisablePlayerControls 1 1 0 0 1 0 0 ; Prevent menu from flickering between button presses	Set iMessageBox to -1 ; Root menuEndBegin GameMode	If iMessageBox	Else;If (iMessageBox == 0)		Return ; Reduce 'cost'	EndIf		If (iMessageBox > 0) ; Positive integer		Set iButton to GetButtonPressed		If (iButton == -1)			Return		Else			Set iMessageBox to (iMessageBox * -1) ; Positive to negative integer			If (iMessageBox == -1)				If (iButton == 0)				ElseIf (iButton == 1)				ElseIf (iButton == 2)				ElseIf (iButton == 3)				ElseIf (iButton == 4)				ElseIf (iButton == 5)				ElseIf (iButton == 6)				ElseIf (iButton == 7)				ElseIf (iButton == 8) ; More					Set iMessageBox to -2				ElseIf (iButton == 9) ; Done					EnablePlayerControls 1 1 0 0 1 0 0					Set iMessageBox to 0				EndIf			ElseIf (iMessageBox == -2)				If (iButton == 0)				ElseIf (iButton == 1)				ElseIf (iButton == 2)				ElseIf (iButton == 3)				ElseIf (iButton == 4)				ElseIf (iButton == 5)				ElseIf (iButton == 6)				ElseIf (iButton == 7) ; More					Set iMessageBox to -3				ElseIf (iButton == 8) ; Back					Set iMessageBox to -1				ElseIf (iButton == 9) ; Done					EnablePlayerControls 1 1 0 0 1 0 0					Set iMessageBox to 0				EndIf			ElseIf (iMessageBox == -3)				If (iButton == 0)				ElseIf (iButton == 1)				ElseIf (iButton == 2)				ElseIf (iButton == 3)				ElseIf (iButton == 4)				ElseIf (iButton == 5)				ElseIf (iButton == 6)				ElseIf (iButton == 7)				ElseIf (iButton == 8) ; Back					Set iMessageBox to -2				ElseIf (iButton == 9) ; Done					EnablePlayerControls 1 1 0 0 1 0 0					Set iMessageBox to 0				EndIf			EndIf		EndIf	Else;If (iMessageBox < 0)		If (fTimer <= 0) ; Pipboy closed			Set fTimer to 0			Set iMessageBox to (iMessageBox * -1) ; Negative to positive integer			If (iMessageBox == 1)				ShowMessage Options01MESG			ElseIf (iMessageBox == 2)				ShowMessage Options02MESG			ElseIf (iMessageBox == 3)				ShowMessage Options03MESG			EndIf		Else			Set fTimer to (fTimer - GetSecondsPassed)		EndIf	EndIfEnd

User avatar
Nathan Hunter
 
Posts: 3464
Joined: Sun Apr 29, 2007 9:58 am


Return to Fallout 3