ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   How to get programmatic access to a control defined in XML (https://www.esoui.com/forums/showthread.php?t=7185)

BoarGules 07/01/17 02:44 AM

How to get programmatic access to a control defined in XML
 
With the friendly help I've received on this forum I've succeeded in putting a scene fragment on the Guild Home screen:

Code:

<GuiXml>
  <Controls>
    <TopLevelControl name="MyFragment" hidden="true">
      <Dimensions x="200" y="200" />
      <Anchor point="BOTTOM" relativeTo="ZO_GuildSharedInfo" relativePoint="BOTTOM" offsetX="120" offsetY="680" />
      <Controls>
        <Label name="$(parent)Label" width="200" height="25" font="ZoFontWinH3" inheritAlpha="true"  color="FFFFFF"
            wrapMode="TRUNCATE" verticalAlignment="TOP" horizontalAlignment="CENTER"  text="some text">
          <Anchor point="TOP" relativeTo="$(parent)" relativePoint="TOP" />
        </Label>
      </Controls>
    </TopLevelControl>
  </Controls>
</GuiXml>

Lua Code:
  1. local fragment = ZO_SimpleSceneFragment:New(MyFragment)
  2. GUILD_HOME_SCENE:AddFragment(fragment)

Now I want to change the text of the label control MyFragmentLabel under program control but I can't work out how to get a reference to it.

sirinsidiator 07/01/17 02:59 AM

That's one of the easier things to do:
Lua Code:
  1. local label
  2. label = MyFragmentLabel
  3. -- or --
  4. label = MyFragment:GetNamedChild("Label")
  5. -- or --
  6. label = GetControl(fragment.control, "Label")
  7. label:SetText("Hello World!")
You named your label control "Label" and it is a child of your "MyFragment" control, so you can just access it via its global variable or relative to the control.

BoarGules 07/01/17 07:01 AM

Thanks, it turns out I was doing the right thing but my error was elsewhere. Knowing that what I was doing really ought to work was the fixed point in the reasoning that I needed.


All times are GMT -6. The time now is 12:17 AM.

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