View Single Post
04/27/15, 07:40 AM   #4
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
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:
  1. 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:
  1. <GuiXml>
  2.     <Controls>
  3.         <TopLevelControl name="Test1" mouseEnabled="true" movable="true">
  4.             <OnInitialized>
  5.                 doStuff(self)
  6.             </OnInitialized>
  7.             <Dimensions x="400" y="400" />
  8.             <Anchor point="CENTER" />
  9.             <Controls>
  10.                 <Backdrop name="myControlBG" inherits="ZO_ThinBackdrop" />
  11.                 <Label name="myControl" font="ZoFontWindowTitle" color="CFDCBD" wrapMode="ELLIPSIS">
  12.                     <AnchorFill />
  13.                 </Label>
  14.             </Controls>
  15.         </TopLevelControl>
  16.     </Controls>
  17. </GuiXml>
+ in LUA
Lua Code:
  1. function doStuff(control)
  2.     mycontrol:SetText(GetUnitName("player")) -- method 1
  3. end


You can also use $(parent), like this :
Lua Code:
  1. <GuiXml>
  2.     <Controls>
  3.         <TopLevelControl name="Test1" mouseEnabled="true" movable="true">
  4.             <OnInitialized>
  5.                 doStuff(self)
  6.             </OnInitialized>
  7.             <Dimensions x="400" y="400" />
  8.             <Anchor point="CENTER" />
  9.             <Controls>
  10.                 <Backdrop name="myControlBG" inherits="ZO_ThinBackdrop" />
  11.                 <Label name="$(parent)CharName" font="ZoFontWindowTitle" color="CFDCBD" wrapMode="ELLIPSIS">
  12.                     <AnchorFill />
  13.                 </Label>
  14.             </Controls>
  15.         </TopLevelControl>
  16.     </Controls>
  17. </GuiXml>
+ in LUA
Lua Code:
  1. function doStuff(control)
  2.     control:GetNamedChild("CharName"):SetText(GetUnitName("player")) -- control is the self object which come from the XML
  3. end
  Reply With Quote