Thread Tools Display Modes
03/26/23, 04:49 PM   #21
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Seriously, you should please follow the rules like all others too.
If you get any error message:

1. Post the whole error message so we can see the error message AND the line numbers AND the exapanded variables from the error mesasge
2. Post your code or at least the code block around the lines of the error message WITH line numbers or at least the line number where the error message hits

We cannot assume things nor do we like to and I personally often do not understand what you talk about in your posted code lines (what should "on editing the text field in the setting panel just below it." relate to in your posted code )

Many thanks for easing it for us all.

I also posted you the "how to read lua error messages" before already so maybe read the info there and learn to read the error messages, or ask questions about the error mesasges in detail so we can explain it to you better. You often, especially for nil errors, find out what's up if you understand the error messages and learn them, instead of ignoring them They tell you what is missing by the error text like "try to index a nil value" -> you got a table which is nil and try to access it somehow before it was created properly with = {}, etc.

Last edited by Baertram : 03/26/23 at 08:42 PM.
  Reply With Quote
03/26/23, 05:01 PM   #22
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Originally Posted by Baertram View Post
Seriously, you should please follow the rules like all others too.
If you get any error message:

1. Post the whole error message so we can see the error message AND the line numbers AND the exapanded variables from the error mesasge
2. Post your code or at least the code block around the lines of the error message WITH line numbers or at least the line number where the error message hits

We cannot assume things nor do we like to and I personally often do not understand what you alk about in your poasted code lines (what should "on editing the text field in the setting panel just below it." relate to in your posted code )

Many thanks for easing it for us all.

I also posted yuteh "how to read lua error messages" before already so maybe read the info there and learn to read the error messages, or ask questions about the error mesasges in detail so we can explain it to you better. You often, especially for nil errors, find out what's up if you understand the error messages and learn them, instead of ignoring them They tell you what is missing by the error text like "try to index a nil value" -> you got a table which is nil and try to access it somehow before it was created properly with = {}, etc.
OK relax I'll do my best to provide.. Is there maybe a better place to ask addon questions? 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. Exuse me I'm not a professional and doin my best!

ERRORS: ill add to bottom of my post as well so they close and handy for all to see and add the codes lines!
Code:
user:/AddOns/MyAddon/MyAddon.lua:248: attempt to index a nil value
stack traceback:
user:/AddOns/MyAddon/MyAddon.lua:248: in function 'MyAddon.SavePlayer'
user:/AddOns/MyAddon/MyAddon.lua:242: in function 'OnSelect'
/EsoUI/Libraries/ZO_ContextMenus/ZO_ContextMenus.lua:476: in function 'ZO_Menu_ClickItem'
user:/AddOns/LibCustomMenu/LibCustomMenu.lua:604: in function 'MouseUp'

Last edited by sinnereso : 03/26/23 at 05:17 PM.
  Reply With Quote
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,912
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
03/26/23, 09:45 PM   #24
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
ty for all of that. I will try to make use of it but it appears none of them solve my solution. If MyAddon_SETTINGS_SAVEDPLAYER_TEXT.data.text doesn't exist yet until the addon options are opened, and CALLBACK_MANAGER:RegisterCallback("LAM-PanelControlsCreated", function(panel) as per its description fires only after all controls are created after its opened then even it wont help me.

What im apparenrly needing is all controls created and existing upon load/reload. Im really not sure how I never noticed this before or if its related to the recent libcustommenu update but this is big problem for me. Its a primary function and having to open addon settings 1st doesn't work for me =p
  Reply With Quote
03/26/23, 10:04 PM   #25
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
MyAddon_SETTINGS_SAVEDPLAYER_TEXT is the reference to the control in my settings menu.

The function having the error is attempting to edit the text on it but apparently cant until the user goes into the addon settings 1st because it doesn't exist yet.

is there a way to make the addon settings and controls exist when the addon loads?
  Reply With Quote
03/27/23, 07:14 AM   #26
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
No.

Why do dou even need your addon to use that control,it only shows in the settings panel? So why should it update before one opens this?
As I said you could add a nil check in your function so it does not try to update that description control at the settings if it does not exist yet.
That way your function still runs even without having the addon settings opened once. And with the Lam Panel Controls Created callback you can update it as someone opens the settings.
  Reply With Quote
03/27/23, 07:28 AM   #27
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Originally Posted by Baertram View Post
No.

Why do dou even need your addon to use that control,it only shows in the settings panel? So why should it update before one opens this?
As I said you could add a nil check in your function so it does not try to update that description control at the settings if it does not exist yet.
That way your function still runs even without having the addon settings opened once. And with the Lam Panel Controls Created callback you can update it as someone opens the settings.
I need it to do this because its informational for the user to know WHO they have saved to port to and mount etc. If they cant remember they can open the settings and see.

im going to try the callback and detect if it exists already or not maybe.. if it doesn't exist yet then just save the variable and be done with it... It might work like this.
  Reply With Quote
03/27/23, 08:03 AM   #28
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
It cannot work by any other way

If settings were not opened the control is nil, so just save without updating the control. As noone opened the settings noone will see the label or tries to see the label, so there is no reason to update it !
If the settings were opened, use the controls created calback, check for YOUR addon's panel and then update the description text of the label.
If it does not dautomatically update by changing the conrol.data.title or control.data.text value, try to change the control.data.title or .text attributes and then call control:UpdateValue() function, it should update the label's text then based on the data table.
  Reply With Quote
03/27/23, 08:48 AM   #29
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Originally Posted by Baertram View Post
It cannot work by any other way

If settings were not opened the control is nil, so just save without updating the control. As noone opened the settings noone will see the label or tries to see the label, so there is no reason to update it !
If the settings were opened, use the controls created calback, check for YOUR addon's panel and then update the description text of the label.
If it does not dautomatically update by changing the conrol.data.title or control.data.text value, try to change the control.data.title or .text attributes and then call control:UpdateValue() function, it should update the label's text then based on the data table.

I would be happy doing that except the settings panel IS getting its data ON_LOAD and storing it someplace during the MyAddon:CreateSettingsWindow(). So whats happening is user logs in and plays etc, then right clicks someone to "Save players @NAME" for my addon use which works fine except the settings panel still shows the OLD @NAME when you open the addon settings. SO it IS getting the data and storing it someplace and then creating the controls with it later when you open the addon settings. I need to find where that place is and edit that when the control data is NIL.

I currently have a temporary fix for people with your idea of detectinf if the data is nil so it just skips it.. addon works fine but cosmetically the settings panel will always show the previous @NAME the 1st time they open addon settings. Infact will always show the previous one until they have opened the addon settings so I can then edit the field properly.

Last edited by sinnereso : 03/27/23 at 08:55 AM.
  Reply With Quote
03/27/23, 12:20 PM   #30
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
I have partially described how to fix that settings panel showing the old value above already, using LibAddonMenu's callback for LAM-PanelControlsCreated.

And if you had looked at the LibAddonMenu WIKI pages I linked above you would have seen there is another callback LAM-PanelOpened, which you could use in to update the label each time your LAM panel opens (Add a nil chck in there as the 1st time it's called maybe before LAM-PanelControlsCreated!).

Both in combination should fix your issues.
  Reply With Quote
03/27/23, 01:27 PM   #31
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
*EDIT*

I got it figured out.. I used the reference for the description field to detect the right addon settings are selected and when its created. Did the job.

Last edited by sinnereso : 03/27/23 at 03:42 PM.
  Reply With Quote
03/27/23, 07:57 PM   #32
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
But my post above explains how to detect it's YOUR addon panel that was created, or opened...
>myPanel is the variable that your addon settings panel returns as you create it via function LibAddonMenu2:RegisterAddonPanel(yourPanelName, yourPanelData) !
---> local myPanel
--- do addon options etc and add it to yourPanelData
---- ... addon controls here
---myPanel = LibAddonMenu2:RegisterAddonPanel(yourPanelName, yourPanelData)
--in the callback functions check for the parameter panel of the callbacks == myPanel or else return

All you need to do now is use the 2 callbacks, "controls created" and "panel opened", check for your panel or else return (as it's another panel then) and then update your descriptions data and use UpdateValue to force the update on it.

I had prepared all that for you already, you just need to take the time and read it, read the Wiki, and try to understand it. If you do not understand it, ask as adviced, instead of reinventing the wheel (which sometimes makes sense for a learning effect but will result in errors in longterm).

Last edited by Baertram : 03/27/23 at 08:00 PM.
  Reply With Quote
03/27/23, 11:17 PM   #33
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
I do thank you very much for all your help. Its very difficult for me to know when what you type is directly the answer or random hypothetical and for me to research for days. I did spend the day on it and came up with this below because i had troule making sense of the panel and myPanel data.

Code:
------ Save player ------
function MyAddon.AddGGFContext(data)
	AddCustomMenuItem("Save to MyAddon", function() MyAddon.SavePlayer(data.displayName) end)
	return
end

function MyAddon.SavePlayer(displayName)
	MyAddon.savedVariables.savedPlayer = displayName
	df("|c6666FF[MyAddon]|r Saving: " .. tostring(displayName))
	if MyAddon_SETTINGS_SAVEDPLAYER_TEXT == nil then--<<< Checking if settings panel has been created
		CALLBACK_MANAGER:RegisterCallback("LAM-PanelControlsCreated", function(panel)
			if MyAddon_SETTINGS_SAVEDPLAYER_TEXT == nil then--<<< Checking if settings panel has been selected
				return
			else
				MyAddon_SETTINGS_SAVEDPLAYER_TEXT.data.text = "Saved Player: " .. tostring(displayName)
				MyAddon_SETTINGS_SAVEDPLAYER_TEXT:UpdateValue()
				return
			end
		end)
		return
	else
		MyAddon_SETTINGS_SAVEDPLAYER_TEXT.data.text = "Saved Player: " .. tostring(displayName)
		MyAddon_SETTINGS_SAVEDPLAYER_TEXT:UpdateValue()
		return
	end
end
this checks the actual description control that im editing in the panel. if it doesnt exist when user saves someone via context menu it saves the variable and registers the callback so when they open addon settings it updates the description field then.

if it does exist then it just saves variable and edits the description field as normal.

I couldnt find a reference that made sense to me for the panel but did have one for the description field so this worked perfectly i think.

What I have seems to work perfectly and is the last bug I can find so im gonna pump it out to the masses but.. i will research this more and look at your suggestion till im blue in the face and see if i can make it work soon.

Last edited by sinnereso : 03/27/23 at 11:29 PM.
  Reply With Quote
03/28/23, 04:21 AM   #34
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
The callback for lam needs to be registered once! In you addons settings code. Not each time in your "SavePlayer" function.

Having it the way you use it now will make the else... execute for each addon, not only yours! If you use 30 addons with settings (or anyone else using your addon does) it will run the panel callback code 30 times for nuts!

Just move the callback code to the lam creation and use the panel parameter of the callback to check if it is your panel as described above in my last post (you get the panel to compare from your lam registerAddonPanel function! After that create the callback for controlsCreated once, and also create the callback for panelOpened to update your description. This will update the description label each time your settings panel opens, so using your player saved function does not need to update that label, unless you use it while the settings panel is actually opened? Then just check if the control is not nil and update directly ).

Last edited by Baertram : 03/28/23 at 04:30 AM.
  Reply With Quote
03/28/23, 07:48 AM   #35
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Here is your RidinDirty.lua file with my changes, hope you understand it better that way seeing the code.
If you got questions, ask

It's untested so please test if it works as expected.
Attached Files
File Type: lua RidinDirty.lua (30.7 KB, 232 views)
  Reply With Quote
03/28/23, 08:58 AM   #36
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Originally Posted by Baertram View Post
The callback for lam needs to be registered once! In you addons settings code. Not each time in your "SavePlayer" function.

Having it the way you use it now will make the else... execute for each addon, not only yours! If you use 30 addons with settings (or anyone else using your addon does) it will run the panel callback code 30 times for nuts!

Just move the callback code to the lam creation and use the panel parameter of the callback to check if it is your panel as described above in my last post (you get the panel to compare from your lam registerAddonPanel function! After that create the callback for controlsCreated once, and also create the callback for panelOpened to update your description. This will update the description label each time your settings panel opens, so using your player saved function does not need to update that label, unless you use it while the settings panel is actually opened? Then just check if the control is not nil and update directly ).
OH WOW! ty.. ill take a look at it right now. And yes the label doesn't need to be changed while in the addon settings so that might work even better. It can only be changed from guild group or friends menus.
  Reply With Quote
03/28/23, 03:48 PM   #37
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Originally Posted by Baertram View Post
Here is your RidinDirty.lua file with my changes, hope you understand it better that way seeing the code.
If you got questions, ask

It's untested so please test if it works as expected.
Just wanted to let you know I spent the day going over your changes and have made sense of it and worked it in with only minor changes mostly to variable and function names to better make sense to me. Seems to be working flawlessly. The default saved variable table was nice touch as well and was something I had planned to do later after all the primary stuff was complete. TY again for all your help.
  Reply With Quote
03/29/23, 05:04 AM   #38
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Glad it worked out, yw. Thanks for the feedback.
  Reply With Quote
03/29/23, 09:22 AM   #39
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
I did just have one other super fast question regarding another function im tuning.. am I doing this correctly?

Code:
local _, isRidingGroupMount, hasFreePassengerSlot = GetTargetMountedStateInfo(savedPlayer)
if isRidingGroupMount == false or hasFreePassengerSlot == false then
     blah blah
end
Im just tweaking error handlers and its all complete finally

**EDIT
Seems to be functioning correctly.

Last edited by sinnereso : 03/29/23 at 11:16 AM.
  Reply With Quote
03/29/23, 01:00 PM   #40
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
You can always have a look at the API documentation txt file
https://wiki.esoui.com/APIVersion#live_API_version
-> link to "API TXT Documentation" .txt file -> Download and open with a text editor

and search for the function name "GetTargetMountedStateInfo" in it.
It will show you the parameters to use and the return variables then:

Code:
* GetTargetMountedStateInfo(*string* _characterOrDisplayName_)
** _Returns:_ *[MountedState|#MountedState]* _mountedState_, *bool* _isRidingGroupMount_, *bool* _hasFreePassengerSlot_
So this function returns 3 parameters.
If you do not need the 1st one "MountedState" you can use the placeholder _ to show that, correct.
And the other 2 return values are _isRidingGroupMount_ and _hasFreePassengerSlot_.

Your code looks okay to me.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Add guild/friend lists context menu item

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