Thread Tools Display Modes
04/30/14, 11:53 PM   #1
Zierk
 
Zierk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 10
Is this a symptom of going too fast? Mail API

Hello,

I am developing an addon that can read, take attachments, take money, and finally delete each piece of mail in your inbox with a single mouse-click on an xml frame. I am getting the following errors from the EsoUI, looking for some help here:

Code:
EsoUI/Ingame/Mail/MailInbox.lua:531: attempt to index a nil value
stack traceback:
EsoUI/Ingame/Mail/MailInbox.lua:531: in function 'MailInbox:RefreshMoneyControls'
EsoUI/Ingame/Mail/MailInbox.lua:562: in function 'MailInbox:OnTakeAttachedMoneySuccess'
EsoUI/Ingame/Mail/MailInbox.lua:51: in function '(anonymous)'
I am using a helper function to identify each mailId and store the "GetMailInfo" data into an array which is called in order to determine if each mail needs to be read, looted or deleted. That information is stored in tables for each category, and event handlers keep the flow running when a mail is read, looted or deleted.

The errors seem to be occurring after the first mail is deleted, as all other mails are read and looted. I've gotten this problem before with previous versions and multiple re-writes of the code to achieve the same end result. Looking for help from the community as I am a new developer and I am not sure how to troubleshoot errors coming from what seems to be the client's LUA functions.
  Reply With Quote
05/01/14, 01:05 AM   #2
Wobin
 
Wobin's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 78
Does the error resolve itself if you slow down your process?

Maybe use zo_callLater(functionName, milisecondDelay) to put in a slight delay
  Reply With Quote
05/01/14, 06:33 AM   #3
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by Zierk View Post
Hello,

I am developing an addon that can read, take attachments, take money, and finally delete each piece of mail in your inbox with a single mouse-click on an xml frame. I am getting the following errors from the EsoUI, looking for some help here:

Code:
EsoUI/Ingame/Mail/MailInbox.lua:531: attempt to index a nil value
stack traceback:
EsoUI/Ingame/Mail/MailInbox.lua:531: in function 'MailInbox:RefreshMoneyControls'
EsoUI/Ingame/Mail/MailInbox.lua:562: in function 'MailInbox:OnTakeAttachedMoneySuccess'
EsoUI/Ingame/Mail/MailInbox.lua:51: in function '(anonymous)'
Well, without posting a part of the code it's slightly impossible to determine what the error is.

I am using a helper function to identify each mailId and store the "GetMailInfo" data into an array which is called in order to determine if each mail needs to be read, looted or deleted. That information is stored in tables for each category, and event handlers keep the flow running when a mail is read, looted or deleted.
Sounds more like a coding error.

Attempt to index a nil value means exactly that.

You have a variable that is nil and your code wants to use it as a table, but you can't search through a nil value.


In example:
myobj:myfunc("bla")

If you get this error in that line, it means myobj is actually nil, not the table/object you expected. Because myobj is nil, it can't search myobj to find myfunc and so it throws the error.


So if your code is
myobj = SomeFunc()
myobj:myfunc("bla")

and you get the error in the myfunc line, then the problem is actually that SomeFunc() returns nil. You would need to figure out why SomeFunc returns nil then.

Next step:
myobj = SomeFunc(mailId)
myobj:myfunc("bla")

So, in this context it would mean mailId is invalid and as it is invalid, the function returns nil but the final crash happens a line later, because you try to actually use the nil object.


Most often the problem is also a simple typo:
mylongobj = SomeFunc(mailId)
...
mylongojb:myfunc("bla")

mylongojb doesn't exist.

HTH

Last edited by Iyanga : 05/01/14 at 06:36 AM.
  Reply With Quote
05/01/14, 04:33 PM   #4
Zierk
 
Zierk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 10
Originally Posted by Wobin View Post
Does the error resolve itself if you slow down your process?

Maybe use zo_callLater(functionName, milisecondDelay) to put in a slight delay
This did resolve the issue for me, I put a counter in the for loop and restricted the amount of processed mail in a single pass to 10, then it delays a second, checks again and if applicable, resolves the next set or ends.



Originally Posted by Iyanga View Post
Well, without posting a part of the code it's slightly impossible to determine what the error is.
In the future, I will include a code example, sorry about that. Thanks for the awesome explanation on nil values and how they occur though!


I was also introduced to http://www.esoui.com/forums/showthread.php?p=2540 which has some good information on how to find these ZO helper functions easier, I didn't even know zo_callLater function existed. I just comb through the API and EVENT pages on the wiki. Learn something new everyday!
  Reply With Quote
05/02/14, 05:55 AM   #5
Teli
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 19
I found that you have to wait for the server to respond to your action before you attempt another one. So you can't just loop through and grab all the attachments in one go. You have to queue each attempt and wait for the event to trigger. before doing another one.

I wrote an addon that grabs all of your attachments from the mail you can check it out the source code here

http://www.esoui.com/downloads/info3...alService.html
  Reply With Quote
05/02/14, 12:23 PM   #6
Zierk
 
Zierk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 10
Originally Posted by Teli View Post
I found that you have to wait for the server to respond to your action before you attempt another one. So you can't just loop through and grab all the attachments in one go. You have to queue each attempt and wait for the event to trigger. before doing another one.

I wrote an addon that grabs all of your attachments from the mail you can check it out the source code here

http://www.esoui.com/downloads/info3...alService.html
Hey thanks for the link, I will check it out and compare functions. I am always willing to learn new tricks of the trade from our experienced developers.
  Reply With Quote
05/02/14, 06:50 PM   #7
Teli
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 19
Originally Posted by Zierk View Post
from our experienced developers.
Thanks I don't think I'm an experienced developer. I'm learning same as you
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Is this a symptom of going too fast? Mail API


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