Thread Tools Display Modes
04/27/15, 05:55 AM   #1
ZunaSW
Join Date: Mar 2014
Posts: 37
Character name in XML

Hello,

So I'm doing more AddOn tests, and I'm finally working on something.
I need to put the character name of the character the player's account is logged in, in a text in an anchor in the XML. So let's say, I have a black anchor, and I want to put the character name of the character I'm playing at the moment in that black anchor.
I think I have to get the name from the Guild Roster and do this in the lua, but I'm not too sure how to do this. I think it is with "GetGuildMemberCharacterInfo(integer guildId, integer memberIndex)"

Any ideas of how can I do this?

Thanks ^^
  Reply With Quote
04/27/15, 06:40 AM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
If you got in XML :

Lua Code:
  1. <Label name="myControl" />

In LUA, it will be :

Lua Code:
  1. mycontrol:SetText(GetUnitName("player"))

There is other ways to do this, but this one is almost quite easy.
  Reply With Quote
04/27/15, 07:12 AM   #3
ZunaSW
Join Date: Mar 2014
Posts: 37
Oh, hm. So I got this, as you say:

Code:
<GuiXml>
    <Controls>
        <TopLevelControl name="Test1" mouseEnabled="true" movable="true">
            <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>
And in the Lua, just what you said in the line 1, yet I get this error:

Code:
user:/AddOns/Test1/Test1.lua:1: attempt to index a nil value
stack traceback:
	user:/AddOns/Test1/Test1.lua:1: in function '(main chunk)'
What am I doing wrong?

Thanks for the reply : )
  Reply With Quote
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
04/27/15, 07:47 AM   #5
ZunaSW
Join Date: Mar 2014
Posts: 37
Ahh, I get it, alright, many thanks : )
  Reply With Quote
04/27/15, 08:01 AM   #6
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
If you need some example code for getting started, you may look at Hello World
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Character name in XML

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off