Quantcast First AddOn problems - ESOUI
Thread Tools Display Modes
08/04/17, 02:57 AM   #1
Join Date: Jul 2015
Posts: 3
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...

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)

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)

EVENT_MANAGER:RegisterForEvent(addon.name, EVENT_ADD_ON_LOADED, onAddonLoaded)
  Reply With Quote
08/04/17, 03:11 AM   #2
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,022
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.


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"
  3. local function WithdrawGold()
  5.     local currMoney = GetBankedCurrencyAmount(CURT_MONEY)
  6.     local goldIcon = "|t70%:70%:EsoUI/Art/currency/currency_gold.dds|t"
  8.     local textGold = ("|cFFFFFF" .. currMoney .. "|r" .. goldIcon)
  10.     local wd = "Withdraw: "
  12.     if currMoney > 0 then
  13.         WithdrawCurrencyFromBank(CURT_MONEY, currMoney)
  14.         d(wd .. textGold)
  15.     end
  17. end
  19. local function OnAddonLoaded(_, addOnName)
  21.     if addOnName == ADDON_NAME then
  22.         EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_OPEN_BANK, WithdrawGold)
  24.     end
  26. end
Obsessive Compulsive Coder

My little french Guild: Cercle de l'Eveil
  Reply With Quote
08/04/17, 03:22 AM   #3
Scootworks's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2014
Posts: 222
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.


EU Server - SŁĄuGhTerHĜuSe
  Reply With Quote
08/05/17, 12:57 PM   #4
Join Date: Jul 2015
Posts: 3
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's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 316
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's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 1,816
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:
  Reply With Quote
08/06/17, 01:21 AM   #7
Join Date: Jul 2015
Posts: 3
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's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,153
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.
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
  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