View Single Post
03/26/23, 08:30 PM   #23
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,994
You tell me you dont like to or have time to answer personal messages and then jump on my forum posts as if they were directed to you personally
I do not need to relax, I'm already fully relaxed.
And yes: I do not need to answer each PM if the info is valuable for others too, that's what forums are made for.
I also provided you the link to the addon devs gitter chat where you could ask the same questions and addon/lua/xml related things, but you do not want to post there, so the forums here are okay.

But if you post here the same rules apply to you as to anyone else: Read before write please!
-> I'm a forum mod, that's why I "jump on your post" (and any others around here!) and I'm just telling you the same as I do write to any other here

Especially if we/I had linked you the ressources already where there is written how to read the lua error messages.
Here you go once again:
https://www.esoui.com/forums/showthread.php?t=8858
-> "lua error messages ingame - How do I read them?"

And how errors should be posted to all of us (not me in particular) so we can understand and help more easily and effectively:
https://www.esoui.com/forums/showthread.php?t=8858
-> "How to report a lua error message/a bug to the developers"


I also adviced you, in case you do not understand the written information/explanation there, to feel free to name us and ask about what you do not understand, and we might be able to help you understand it (better).
This got nothing to do with being a professional developer (neither am I) or not, that's communication and if you are willing to learn we are willing to help.


As an exaplanation: The error says
user:/AddOns/MyAddon/MyAddon.lua:248: attempt to index a nil value

So the error happens in file MyAddon/MyAddon.lua line 248
As I wrote before it's about "index a nil value" -> means there is a variable in that line which should be a table, but it does not exist.

Your line 248 is:
MyAddon_SETTINGS_SAVEDPLAYER_TEXT.data.text = "Saved Player: " .. tostring(displayName)-- ERRORS APPEAR TO BE HERE AND BELOW REPORTING NIL VALUE FOR IM ASSUMING "displayName"

So what is a table in this line?
MyAddon_SETTINGS_SAVEDPLAYER_TEXT for example is
Or MyAddon_SETTINGS_SAVEDPLAYER_TEXT.data is too
Any of these seems to be nil at the point where the error happens.

So either MyAddon_SETTINGS_SAVEDPLAYER_TEXT or MyAddon_SETTINGS_SAVEDPLAYER_TEXT.data does not exist.
Add some d(tostring(MyAddon_SETTINGS_SAVEDPLAYER_TEXT)) or d(tostring(MyAddon_SETTINGS_SAVEDPLAYER_TEXT.data)) to see which one is nil.
And then work yor way back from the error (the error message shows you the "call stack -> from bottom to top where the error occurs) to the start and check where your variables MyAddon_SETTINGS_SAVEDPLAYER_TEXT and MyAddon_SETTINGS_SAVEDPLAYER_TEXT.data are properly created and filled.

Keep in mind that lua does not know local defined variables if they are defined after the calling code, or inside any if .. end, for .. do, or other closure, and you want to use the same variable otuside of the closure!
Either define MyAddon_SETTINGS_SAVEDPLAYER_TEXT at the top of your addon file MyAddon.lua, as a local.
And also define MyAddon_SETTINGS_SAVEDPLAYER_TEXT.data there as {} empty tbale directly.
Or at least once before it is tried to be accessed in line 248 finally.


btw: Looks like MyAddon_SETTINGS_SAVEDPLAYER_TEXT is a LibAddonMenu control you wan to create for your settings panel?
It's not accessible before the addon panel was loaded!!!
Before it's simply nil.

LibAddonMenu provides a callback that fires as the panel get's loaded, and as the controls were created. So you could use that to see if the control was created:
https://www.esoui.com/downloads/info7-LibAddonMenu.html
-> WIKI about callbacks: https://github.com/sirinsidiator/ESO...LAM2-callbacks

But basically you do not need to manually update MyAddon_SETTINGS_SAVEDPLAYER_TEXT if it got a getFunc. Just let it read the actual value from your SavedVariables there.
But as the control is a description it got no getFunc so you need to manually update it.
-> Thus you need to use LibAddonMenu's callback for PanelControlsCreated to update it for the first time, as your panel was loaded and all controls were build properly.
Be carefull with that callback functions, as it will run for EACH addon once! So you must check the panel loaded is yours as described or it will run too often.

Lua Code:
  1. CALLBACK_MANAGER:RegisterCallback("LAM-PanelControlsCreated", function(panel)
  2.     if panel ~= myPanel then return end
  3.     -- do something
  4. end)

myPanel is the variable that your addon settings panel returns as you create it via function LibAddonMenu2:RegisterAddonPanel(yourPanelName, yourPanelData) !

In order to let the callbacks work properly you night need to add the registerForRefresh at yourPanelData table! Check the Wiki documentation if this is needed for the LAM-PanelControlsCreated calback please.


And in your function where you try to access MyAddon_SETTINGS_SAVEDPLAYER_TEXT you need to check if it's nil or not!

Lua Code:
  1. if MyAddon_SETTINGS_SAVEDPLAYER_TEXT ~= nil then
  2.  ---update it
  3. end

Last edited by Baertram : 03/26/23 at 08:46 PM.
  Reply With Quote