I've made a script that displays a series of menus to the player. After he chooses how much time he wants to pass, the GameDaysPassed variable is modified by the appropriate amount.
Scriptname LichSoulHibernationActivatorScript extends ObjectReference Actor Property Player Auto ; It is preferred to have a direct reference to the player at all times for optimization purposes.GlobalVariable Property GameDaysPassed AutoMessage Property Lich02HibernationOptionsMainMenu AutoMessage Property Lich02HibernationOptionsDays AutoMessage Property Lich02HibernationOptionsWeeks AutoMessage Property Lich02HibernationOptionsMonths AutoMessage Property Lich02HibernationOptionsYears AutoState Activated ; NO CODE DESIRED.EndStateAuto State NotActivated Event OnActivate(ObjectReference akActionRef) ; Prevent further activations, just in case GoToState("Activated") ; Set value of gamedayspassed to a local variable for optimization purposes float gdpLocalVar = GameDaysPassed.GetValue() ; Loop the main menu until told to quit Bool ExitMenu = False While ExitMenu != True ; We only want to loop if told to by the player, so flip the flag automatically after each loop ExitMenu = True ; Display the Main Menu int MainMenuButton = Lich02HibernationOptionsMainMenu.Show() if MainMenuButton == 0 ; Player has selected days ; Get the number of days to advance from the Player int SubMenuButton = Lich02HibernationOptionsDays.Show() ; As long as the Player has not chosen to cancel or return to the main menu, we add gamedays to their current date based on the button pressed if SubMenuButton != 7 || SubMenuButton != 8 ; Add gamedays to the current date Debug.MessageBox("GDP: " + GameDaysPassed.GetValue() + ". gdpLocalVar: " + gdpLocalVar + ". New GDP:" + (gdpLocalVar + (SubMenuButton+1))) GameDaysPassed.SetValue(gdpLocalVar + (SubMenuButton + 1)) ElseIf SubMenuButton == 7 ; Loop and show the menu once more ExitMenu = False EndIf ElseIf MainMenuButton == 1 ; Player has selected weeks ; Get the number of weeks to advance from the Player int SubMenuButton = Lich02HibernationOptionsWeeks.Show() ; As long as the Player has not chosen to cancel or return to the main menu, we add gamedays to their current date based on the button pressed if SubMenuButton != 5 || SubMenuButton != 6 ; Add gamedays to the current date GameDaysPassed.SetValue(gdpLocalVar + ((SubMenuButton + 1) * 7)) ElseIf SubMenuButton == 5 ; Loop and show the menu once more ExitMenu = False EndIf ElseIf MainMenuButton == 2 ; Player has selected months ; Get the number of months to advance from the Player int SubMenuButton = Lich02HibernationOptionsMonths.Show() ; As long as the Player has not chosen to cancel or return to the main menu, we add gamedays to their current date based on the button pressed if SubMenuButton != 5 || SubMenuButton != 6 ; Add gamedays to the current date GameDaysPassed.SetValue(gdpLocalVar + (((SubMenuButton + 1) * 7) * 4.2)) ElseIf SubMenuButton == 5 ; Loop and show the menu once more ExitMenu = False EndIf ElseIf MainMenuButton == 3 ; Player has selected years ; Get the number of years to advance from the Player int SubMenuButton = Lich02HibernationOptionsYears.Show() ; As long as the Player has not chosen to cancel or return to the main menu, we add gamedays to their current date based on the button pressed if SubMenuButton != 5 || SubMenuButton != 6 ; Add gamedays to the current date GameDaysPassed.SetValue(gdpLocalVar + (((SubMenuButton + 1) * 7) * 52)) ElseIf SubMenuButton == 5 ; Loop and show the menu once more ExitMenu = False EndIf EndIf EndWhile ; Return state to normal GoToState("NotActivated") EndEventEndStateHowever, it does not work. The menus all work fine, but GameDaysPassed is never modified/
If you noticed, in the middle of one of the menus, I use this code:
Debug.MessageBox("GDP: " + GameDaysPassed.GetValue() + ". gdpLocalVar: " + gdpLocalVar + ". New GDP:" + (gdpLocalVar + (SubMenuButton+1)))That line, when shown in game, prints the correct value. The calculation is correct, however, it is not actually applied to the global variable. GameDaysPassed always remains the same. I checked in the editor to make sure it wasn't constant, which it isn't, so I'm not entirely sure what is wrong.
Anyone have any ideas or possible alternatives?
