Lua Code:
local addon.name = "BankAllGoldWithdraw"
addon.name cannot be declared. it's addon you should declare as a table and then subtable name.
like
Lua Code:
local addon = [}
addon.name = "BankAllGoldWithdraw"
After a table for 1 variable, is not really good.
just use
Lua Code:
local ADDON_NAME = "BankAllGoldWithdraw"
and it'll be okay.
Lua Code:
local GoldIcon = "|t70%:70%:EsoUI/Art/currency/currency_gold.dds|t"
you should avoid declaring variables which are only used in a block (here your function withdrawGold() outside of your function, especially if it don't require to be outside of it.
A little convention created by zos is to capitalize function names and lowercase first letter of variable names.
Also, please avoid usage of perenthesis if they're not useful. In Lua they are only needed for operator priority changes.
so I would write your code :
Lua Code:
local ADDON_NAME = "BankAllGoldWithdraw"
local function WithdrawGold()
local currMoney = GetBankedCurrencyAmount(CURT_MONEY)
local goldIcon = "|t70%:70%:EsoUI/Art/currency/currency_gold.dds|t"
local textGold = ("|cFFFFFF" .. currMoney .. "|r" .. goldIcon)
local wd = "Withdraw: "
if currMoney > 0 then
WithdrawCurrencyFromBank(CURT_MONEY, currMoney)
d(wd .. textGold)
end
end
local function OnAddonLoaded(_, addOnName)
if addOnName == ADDON_NAME then
EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_OPEN_BANK, WithdrawGold)
EVENT_MANAGER:UnregisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED)
end
end