View Single Post
08/04/17, 03:11 AM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
Lua Code:
  1. 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:
  1. local addon = [}
  2. addon.name = "BankAllGoldWithdraw"

After a table for 1 variable, is not really good.

just use
Lua Code:
  1. local ADDON_NAME = "BankAllGoldWithdraw"
and it'll be okay.


Lua Code:
  1. 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.

Lua Code:
  1. if (currMoney > 0) then
Lua Code:
  1. if currMoney > 0 then



so I would write your code :

Lua Code:
  1. local ADDON_NAME = "BankAllGoldWithdraw"
  2.  
  3. local function WithdrawGold()
  4.  
  5.     local currMoney = GetBankedCurrencyAmount(CURT_MONEY)
  6.     local goldIcon = "|t70%:70%:EsoUI/Art/currency/currency_gold.dds|t"
  7.  
  8.     local textGold = ("|cFFFFFF" .. currMoney .. "|r" .. goldIcon)
  9.    
  10.     local wd = "Withdraw: "
  11.        
  12.     if currMoney > 0 then
  13.         WithdrawCurrencyFromBank(CURT_MONEY, currMoney)
  14.         d(wd .. textGold)
  15.     end
  16.    
  17. end
  18.  
  19. local function OnAddonLoaded(_, addOnName)
  20.  
  21.     if addOnName == ADDON_NAME then
  22.         EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_OPEN_BANK, WithdrawGold)
  23.         EVENT_MANAGER:UnregisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED)
  24.     end
  25.    
  26. end
  Reply With Quote