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.
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
...