Thread Tools Display Modes
08/04/17, 02:57 AM   #1
clawe
Join Date: Jul 2015
Posts: 5
First AddOn problems

Hello. I'm writing my first AddOn for my personal use.
The idea is pretty simple. I want to automatically withdraw all gold from bank.

Inspired by few other banking addons I've wrote some code.
At first it worked but after some changes I cant get it to work.
I was so stupid that forgot to backup working version.

If you could help me it would be great...

Code:
local addon.name = "BankAllGoldWithdraw"
local GoldIcon = "|t70%:70%:EsoUI/Art/currency/currency_gold.dds|t"

local function withdrawGold()

	local currMoney = GetBankedCurrencyAmount(CURT_MONEY)
	
	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(event, 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

EVENT_MANAGER:RegisterForEvent(addon.name, EVENT_ADD_ON_LOADED, onAddonLoaded)
  Reply With Quote
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
08/04/17, 03:22 AM   #3
Scootworks
 
Scootworks's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2014
Posts: 312
the problem he has is in general: he will withdraw the whole money from the bank. i think that's not he's idea. so you need to withdraw a difference from your bag to the value that you want to keep.

MONEY_YOU_WANT_TO_KEEP_IN_YOUR_BAG = 15000
CURRENT_MONEY_IN_YOUR_BAG = 3000

WITHDRAW_VALUE = MONEY_YOU_WANT_TO_KEEP_IN_YOUR_BAG - CURRENT_MONEY_IN_YOUR_BAG
  Reply With Quote
08/05/17, 12:57 PM   #4
clawe
Join Date: Jul 2015
Posts: 5
That was and idea. To withdraw all gold.

Thanks Ayantir for all suggestions.
Unfortunately addon still doesn't work.

It looks like function does not fire or event is not registered.
  Reply With Quote
08/05/17, 02:16 PM   #5
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 408
What is the error? Looking at the error can be helpful, because it tells you what type of thing is happening, and it can also point you to the location where it is happening.

Is there no error at all? It's possible your functions aren't running. Peppering d() throughout your addon can help you determine what is not running.
  Reply With Quote
08/05/17, 03:25 PM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,913
What Ayantir has stripped in his code was the addon loaded event lines at the bottom.
Did you put them into your addon again so it is "starting" at all?

Lua Code:
  1. EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED, onAddonLoaded)
  Reply With Quote
08/06/17, 01:21 AM   #7
clawe
Join Date: Jul 2015
Posts: 5
There is no error displayed, addon just doesn't work.

I've noticed that missing line and added it myself.

No luck so far. Strange.
  Reply With Quote
08/06/17, 02:02 AM   #8
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,567
Try to put error("hello world") into the first line of your lua file. If that doesn't show ingame, you have a problem with your basic addon structure, otherwise try to put it into the loaded event next and see what happens, etc.
If that doesn't help either, you should upload your addon somewhere and link it here, so we can see the whole thing and won't have to guess at the problem.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » First AddOn problems

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off