ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Character name in XML (https://www.esoui.com/forums/showthread.php?t=4657)

ZunaSW 04/27/15 05:55 AM

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

Ayantir 04/27/15 06:40 AM

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.

ZunaSW 04/27/15 07:12 AM

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 : )

Ayantir 04/27/15 07:40 AM

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

ZunaSW 04/27/15 07:47 AM

Ahh, I get it, alright, many thanks : )

votan 04/27/15 08:01 AM

If you need some example code for getting started, you may look at Hello World


All times are GMT -6. The time now is 05:24 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI