06/01/20, 04:07 PM | #1 | |
Join Date: Jun 2020
Posts: 6
|
Variable in the table returns nil
Hello!
I am learning to create add-ons and ran into a problem. When I try to get a variable from any table, I get nil Even if I try to get the variable myAddon.name Lua Code:
|
|
06/01/20, 04:16 PM | #2 |
Cannot see any reason from the code except that myAddon is not "unique" and every other of your active addons could define such a variable
Better choose something unique like "MyAddonForTest1" or similar or make sure all other addons are disabled as you test. What line is the error message telling you the error is? Please copy&paste post the complete error message from the error popup. You should also "expand" the error message so you can see the stack traceback (what way the loading of the functions took) and the variables and their contents. There you are able to see on first sight if any variable, and which one, does not have the value you did expect it has. Also make sure the folder name and the manifest txt file name of your addon are exactly the same! Oh and whereever you have taken the example from please do not use ZO_SavedVars:New for character SavedVariables anymore as these will use the charactername and are not rename safe. Better use ZO_SavedVars:NewCharacterIdSettings instead now. |
|
06/01/20, 04:24 PM | #3 | ||
Join Date: Jun 2020
Posts: 6
|
Lua Code:
This function sends nil to the chat, although it should send myAddon I checked the name of the myAddon folder Moreover, I disabled all add-ons during the test. Thanks for the advice. I will use ZO_SavedVars: NewCharacterIdSettings |
||
06/01/20, 04:29 PM | #4 |
Move the line here into your function event_add_on_laoded callback!
Lua Code:
It's currently called too early as it seems and not related to your addon. Better register events AFTER your addon has loaded via event_add_on_loaded, means after this line: if addonName ~= myAddon.name then return end Lua Code:
This makes sure your SavedVAriables have been loaded as well BEFORE the player activated event callback fires for your addon. |
|
06/01/20, 04:44 PM | #5 | ||
Join Date: Jun 2020
Posts: 6
|
But this did not solve the problem. As I saw nil in the chat instead of myAddon, I see it. |
||
06/01/20, 04:45 PM | #6 |
Do you have an xml file with a control which is also named "myAddon"? If so, it's overwriting your global table with the control.
|
|
06/01/20, 04:49 PM | #7 | ||
Join Date: Jun 2020
Posts: 6
|
Xml Code:
Here is my XML GUI |
||
06/01/20, 04:58 PM | #8 | |
Join Date: Jun 2020
Posts: 6
|
I am an idiot!
I have a settings.lua file that creates the settings panel via libaddonmenu. So in Lua Code:
Changed and it worked. @sirinsidiator thanks for pushing everything to check! @Baertram thanks for the good tips! |
|
ESOUI » Developer Discussions » Lua/XML Help » Variable in the table returns nil |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|