For context this is part of a HUD UI for my mecha game. And there are 4 hardpoints where you can fit weapons and each weapon also has different modes which need to be displayed. Currently I use several if statements to output the correct values however in my experience from unity they have a system where you can directly reference other objects and act accordingly on those references. My issue here is how long the code is and using several what I find to be unnecessary if statements. Is there any way for me to cut down code like this?
local function updateHUD()
task.wait(.05)
--print(Gun:GetAttribute("Mode"))
if Gun:GetAttribute("Hardpoint") == "LH" then
--print(Gun:GetAttribute("Mode"))
if Mode.Value == "Alt" then
--print("Switched to Alt")
HUD.ARML.AMMO.Text = Gun.AltAmmo.Value
HUD.ARML.MODE.FIREMODE.Text = Settings.ALT_AMMO_TYPE
elseif Mode.Value == "Safe" then
--print("Switched to Safe")
HUD.ARML.AMMO.Text = "----"
HUD.ARML.MODE.FIREMODE.Text = "SAFE"
elseif Mode.Value == "Pri" then
--print("Switched to Pri")
HUD.ARML.AMMO.Text = Gun.PriAmmo.Value
HUD.ARML.MODE.FIREMODE.Text = Settings.AMMO_TYPE
end
elseif Gun:GetAttribute("Hardpoint") == "RH" then
--print(Gun:GetAttribute("Mode"))
if Mode.Value == "Alt" then
--print("Switched to Alt")
HUD.ARMR.AMMO.Text = Gun.AltAmmo.Value
HUD.ARMR.MODE.FIREMODE.Text = Settings.ALT_AMMO_TYPE
elseif Mode.Value == "Safe" then
--print("Switched to Safe")
HUD.ARMR.AMMO.Text = "----"
HUD.ARMR.MODE.FIREMODE.Text = "SAFE"
elseif Mode.Value == "Pri" then
--print("Switched to Pri")
HUD.ARMR.AMMO.Text = Gun.PriAmmo.Value
HUD.ARMR.MODE.FIREMODE.Text = Settings.AMMO_TYPE
end
elseif Gun:GetAttribute("Hardpoint") == "LP" then
--print(Gun:GetAttribute("Mode"))
if Mode.Value == "Alt" then
--print("Switched to Alt")
HUD.PYLONL.AMMO.Text = Gun.AltAmmo.Value
HUD.PYLONL.MODE.FIREMODE.Text = Settings.ALT_AMMO_TYPE
elseif Mode.Value == "Safe" then
--print("Switched to Safe")
HUD.PYLONL.AMMO.Text = "----"
HUD.PYLONL.MODE.FIREMODE.Text = "SAFE"
elseif Mode.Value == "Pri" then
--print("Switched to Pri")
HUD.PYLONL.AMMO.Text = Gun.PriAmmo.Value
HUD.PYLONL.MODE.FIREMODE.Text = Settings.AMMO_TYPE
end
elseif Gun:GetAttribute("Hardpoint") == "RP" then
--print(Gun:GetAttribute("Mode"))
if Mode.Value == "Alt" then
--print("Switched to Alt")
HUD.PYLONR.AMMO.Text = Gun.AltAmmo.Value
HUD.PYLONR.MODE.FIREMODE.Text = Settings.ALT_AMMO_TYPE
elseif Mode.Value == "Safe" then
--print("Switched to Safe")
HUD.PYLONR.AMMO.Text = "----"
HUD.PYLONR.MODE.FIREMODE.Text = "SAFE"
elseif Mode.Value == "Pri" then
--print("Switched to Pri")
HUD.PYLONR.AMMO.Text = Gun.PriAmmo.Value
HUD.PYLONR.MODE.FIREMODE.Text = Settings.AMMO_TYPE
end
end
end