From cc11aa25b73ee3aa6e69c58123079e5d07e13124 Mon Sep 17 00:00:00 2001 From: WantedDV <122710241+WantedDV@users.noreply.github.com> Date: Sun, 23 Apr 2023 00:25:30 -0230 Subject: [PATCH 1/2] check if button exists first --- data/ui_scripts/frontend_menus/utils.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/data/ui_scripts/frontend_menus/utils.lua b/data/ui_scripts/frontend_menus/utils.lua index 7abe1926..f394e0ae 100644 --- a/data/ui_scripts/frontend_menus/utils.lua +++ b/data/ui_scripts/frontend_menus/utils.lua @@ -17,6 +17,9 @@ local SetButtonState = function(button, state) end local RemoveButton = function(buttonTable, button) + if not button then + return + end for id, v in pairs(buttonTable) do if buttonTable[id].optionDisplay == button.stringRef then table.remove(buttonTable, id) @@ -31,6 +34,9 @@ local RemoveSpaces = function(buttonTable) end local GetButtonIndex = function(buttonTable, button) + if not button then + return nil + end for id, v in pairs(buttonTable) do if buttonTable[id].optionDisplay == button.stringRef then return id From 454ca4adf2205bf41a6cac45ec94f2364079399f Mon Sep 17 00:00:00 2001 From: WantedDV <122710241+WantedDV@users.noreply.github.com> Date: Sun, 23 Apr 2023 11:08:54 -0230 Subject: [PATCH 2/2] do not use arithmetic operator if button index nil - cleanup unnecessary explicit index --- data/ui_scripts/frontend_menus/__init__.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/data/ui_scripts/frontend_menus/__init__.lua b/data/ui_scripts/frontend_menus/__init__.lua index 7ee38ff2..30cba4f5 100644 --- a/data/ui_scripts/frontend_menus/__init__.lua +++ b/data/ui_scripts/frontend_menus/__init__.lua @@ -87,7 +87,10 @@ end local addCustomButtons = function(controller, menuId, buttonTable, isLeader) if menuId == LobbyData.UITargets.UI_MPLOBBYMAIN.id then utils.RemoveSpaces(buttonTable) - utils.AddSpacer(buttonTable, utils.GetButtonIndex(buttonTable, CoD.LobbyButtons.THEATER_MP) - 1) + local theaterIndex = utils.GetButtonIndex(buttonTable, CoD.LobbyButtons.THEATER_MP) + if theaterIndex ~= nil then + utils.AddSpacer(buttonTable, theaterIndex - 1) + end end if menuId == LobbyData.UITargets.UI_MPLOBBYONLINE.id or menuId == LobbyData.UITargets.UI_ZMLOBBYONLINE.id then @@ -121,11 +124,14 @@ local addCustomButtons = function(controller, menuId, buttonTable, isLeader) if menuId == LobbyData.UITargets.UI_ZMLOBBYONLINE.id then utils.RemoveButton(buttonTable, CoD.LobbyButtons.THEATER_ZM) - utils.AddLargeButton(controller, buttonTable, CoD.LobbyButtons.THEATER_ZM, #buttonTable + 1) + utils.AddLargeButton(controller, buttonTable, CoD.LobbyButtons.THEATER_ZM) utils.RemoveSpaces(buttonTable) utils.AddSpacer(buttonTable, utils.GetButtonIndex(buttonTable, CoD.LobbyButtons.SERVER_BROWSER)) - utils.AddSpacer(buttonTable, utils.GetButtonIndex(buttonTable, CoD.LobbyButtons.ZM_BUBBLEGUM_BUFFS) - 1) + local bgbIndex = utils.GetButtonIndex(buttonTable, CoD.LobbyButtons.ZM_BUBBLEGUM_BUFFS) + if bgbIndex ~= nil then + utils.AddSpacer(buttonTable, bgbIndex - 1) + end utils.AddSpacer(buttonTable, utils.GetButtonIndex(buttonTable, CoD.LobbyButtons.STATS)) end end