Attempt to index a nil value confusion
Hi all.
I'm trying to access an variable with a value from my saved variables, but ESO is complaining that the variable is nil. This is the line in question: Lua Code:
This is executed by a function fired by EVENT_INVENTORY_SINGLE_SLOT_UPDATE. If this line is not present, references just a few lines down in the same function to other items in my saved variables are picked up just fine. The error also only comes up at login, but not after a ui reload. I've tried deleting the saved variables .lua file and starting from scratch, but still this issue persists. Any help would be greatly appreciated! |
Is the variable for your SavedVars properly initialized before this?
The error is happening because either Imperialization is nil or Imperialization.savedVariables is nil. (Also check for typo in those two. Always happens when you least expect it...) |
And remember you can safeguard your code
if Imperialization.savedVariables then if Imperialization.savedVariables.ConvertOnEquip then -- do your stuff end else d("Error No Saved Variables here") end When you do a test like "if <variable> then" ,the code will only run if the variable is not nil or not false (nil = means not initialized) |
The easiest way to fix this issue is to register event after you have saved variables available - i.e. move event registration to the Initialize function:
Lua Code:
By the way I think it's not a good idea to use addon version as a version of your saved variables. It will reset everything to the defaults with each new addon version. EDIT: Another suggestion - Conditions you use looks rather complicated. If you use itemSyle as a key in your saved variables, you can use much easier condition: lua Code:
|
Quote:
Now that it has been pointed out the mistake seems silly. And yes, my conditions quickly got out of hand:D Now seems like the best time to reign all of this stuff back in. |
All times are GMT -6. The time now is 08:33 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI