You need to do a check like this:
This uses the pre-existing SVs or creates an empty table if there are none.
You can also improve your slashcmdhandler like this:
lua Code:
local COMMAND_PARAMS = {
hide = function()
if TXPVisible then
TXPVisible=false
TribalExperienceBar:Hide()
print("Experience hidden, type /TXP show to show.")
end
end,
show = function()
if not TXPVisible then
TXPVisible=true
TribalExperienceBar:Show()
print("Experience displayed, type /TXP hide to hide.")
end
end,
rested = function()
if GetXPExhaustion() == nil then
print("You have no rested EXP.")
else
print("You have "..GetXPExhaustion().." rested EXP remaining.")
end
end,
lock = function()
if TXPLocked == true then
TXPLocked = false
print("TXP UNlocked")
elseif TXPLocked == false then
TXPLocked = true
print("TXP Locked")
end
end,
curve = function()
if TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\curve") == true then
TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\curve")
print("Texture already set to Curve")
elseif TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\curve") == false then
TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\curve")
print("Texture set to Curve")
end
end,
simple = function()
if TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\simple") == true then
TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\simple")
print("Texture already set to Simple")
elseif TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\simple") == false then
TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\simple")
print("Texture set to Simple")
end
end,
split = function()
if TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\split") == true then
TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\split")
print("Texture already set to Split")
elseif TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\split") == false then
TribalExperienceBar:SetStatusBarTexture("Interface\\AddOns\\TXP\\media\\split")
print("Texture set to Split")
end
end,
}
local function slashcmdhandler(param)
if COMMAND_PARAMS[param] then
COMMAND_PARAMS[param]()
return
end
print("Valid commands are:");
print("/TXP show (Show the experience bar.)");
print("/TXP hide (Hide the experience bar.)");
print("/TXP rested (Shows the amount of rested XP.)");
print("/TXP Lock (Locks the experience bar if it is unlocked, Unlocks it if it is locked.")
print("/TXP Curve (Sets the status bar texture to Curve.")
print("/TXP Simple (Sets the bar texture to Simple")
print("/TXP Split (Sets the Bar texture to Split")
end
This works by doing a simple table lookup and quickly coming back with a result or nil, instead of testing each check in an if-else chain.