View Single Post
06/06/20, 01:07 PM   #1
stolen6394
Join Date: Jun 2020
Posts: 3
Access to addon's table in OnInitialized callback?

Hi, I am a newbie writing my first addon and having a seriously difficult time and fun at the same time.

I'm not a native English speaker, so please let me know if what I wrote is unclear or misleading.

So here is the situation,

I made 4 files (two .lua, .xml and .txt)
and one of the .lua files makes a table (e.g., MYAddOnTable in the code below)
and the other one does what addons normally do (registering events... etc.)

the .txt file lists the files in the following order:
Code:
##... Title... APIVersion... etc.

MakingTable.lua
MyAddOn.xml
DoAddonJob.lua
In the xml:
Code:
... GuiXml... TopLevelControl... Backdrop...
    <Label ...attributes...>
        <Anchor .../>
            <OnInitialized>
                MyAddOnTable.foo()
            </OnInitialized>
....
I thought "since MakingTable.lua will be loaded first before the xml file is loaded,
so MyAddOnTable.foo() will be successfully invoked. great!"

but it turned out that MyAddOnTable is evaluated as nil at that moment.
I figured it out by modifying the code as follows:

Code:
<OnInitialized>
    FOO = 1
    BAR = MyAddOnTable
</OnInitialized>
and in the game, I typed "/script d(FOO)" and it said 1, (so the script must have been invoked anyway)
then I typed "/script d(BAR)" and it said nil. (meaning MyAddOnTable is evaluated as nil?)

I am confused.

Is there any way to get access to my addon's table in the OnInitialized callback?
or am I missing something?

Thanks in advance.
  Reply With Quote