Sometimes I hate this :)
So, I'm cleaning up my add-on by shifting more code (such as registering events) to their own functions, then calling them as necessary. I shifted the code that defines my top down window and the label control for my info bar into its own function. The label control is updated every tick.
Here's my crux. The add-on works still, but I'm getting a nil function error on the call to the label in the update function. Oddly, if I dismiss the error five times, it goes away until the next reload. So, inside function: MS.toolText = WM:CreateControl("lsGoldT",statWin,CT_LABEL) In update function: MS.toolText:SetText(MS.globals.barString) This worked with no errors if I defined MS.toolText outside a function. |
Are you creating your IsGoldT control before the OnUpdate handler is set?
|
Using OnUpdate in the xml. Should I move it out of there?
|
I don't know. Is MS.toolText being created before the OnUpdate script is defined?
|
Yes, the function that creates it is being called in my initialization function, which is called with EVENT_ADD_ON_LOADED. Is it possible that the update handler is being called before that?
EDIT: Just for clarification, this is the current order of things in my add-on: Initial Declarations Initialization Function - Calls functions to register events post-add-on start, setup the initial variable values, and create the bar EVENT_ADD_ON_LOADED is registered - calls the above mentioned Init function Function to create toolbar - creates top level window, then creates MS.toolText Function for registering events post load - called from init function above Function to setup initial variables - called from init function above Helper function for counting saved variables Update Handler Function ... |
So your OnUpdate handler is set in the main chunk of the addon? Not during or after the EVENT_ADD_ON_LOADED event? ;)
|
Quote:
What I did:
The funny thing is that the add on still works after you clear the errors out. Typically something that give an error about getting nil when it expects something else indicates something is broken and the add on doesn't work. |
EVENT_ADD_ON_LOADED fires when your addon has finished loading and your previously saved variables are ready to be accessed. Assume this is your addon below - I'll comment the order in which everything occurs.
YourAddon.txt Code:
## Title: YourAddon Lua Code:
YourAddon.xml - this file is executed from top to bottom Code:
<GuiXml> Now... this isn't the exact format that you described your addon to be, but am I close? Do you see the error(s)? |
Yes, so it was when I removed the control definitions into a function. When they were globals they were defined before my OnUpdate handler.
|
"globals" is the wrong term, but yes. It was a scoping issue.
|
Aye, and thanks to you it is now completely fixed.
|
Wonderful. :)
|
All times are GMT -6. The time now is 07:53 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI