Because doing like this need that you write the lua code in your function which will be executed when addon will be loaded. (with event_add_on_loaded).
If you write
Lua Code:
mycontrol:SetText(GetUnitName("player"))
and your LUA file is before your XML file in the metdata (.txt file). You'll get the error you quoted.
Another way of doing this is :
Lua Code:
<GuiXml>
<Controls>
<TopLevelControl name="Test1" mouseEnabled="true" movable="true">
<OnInitialized>
doStuff(self)
</OnInitialized>
<Dimensions x="400" y="400" />
<Anchor point="CENTER" />
<Controls>
<Backdrop name="myControlBG" inherits="ZO_ThinBackdrop" />
<Label name="myControl" font="ZoFontWindowTitle" color="CFDCBD" wrapMode="ELLIPSIS">
<AnchorFill />
</Label>
</Controls>
</TopLevelControl>
</Controls>
</GuiXml>
+ in LUA
Lua Code:
function doStuff(control)
mycontrol:SetText(GetUnitName("player")) -- method 1
end
You can also use $(parent), like this :
Lua Code:
<GuiXml>
<Controls>
<TopLevelControl name="Test1" mouseEnabled="true" movable="true">
<OnInitialized>
doStuff(self)
</OnInitialized>
<Dimensions x="400" y="400" />
<Anchor point="CENTER" />
<Controls>
<Backdrop name="myControlBG" inherits="ZO_ThinBackdrop" />
<Label name="$(parent)CharName" font="ZoFontWindowTitle" color="CFDCBD" wrapMode="ELLIPSIS">
<AnchorFill />
</Label>
</Controls>
</TopLevelControl>
</Controls>
</GuiXml>
+ in LUA
Lua Code:
function doStuff(control)
control:GetNamedChild("CharName"):SetText(GetUnitName("player")) -- control is the self object which come from the XML
end