Thread Tools Display Modes
12-05-15, 03:33 PM   #1
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
XML and Lua

Hey guys,

I'm trying to get my frame from my XML file to show via Lua code. This is what I have so far.

Code:
<Frame name="TrackerDialog" hidden="true" virtual="true" frameStrata="DIALOG" parent="UIParent">
        <Size x="200" y="325"/>
        </Size>
        <Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background-Dark" edgeFile="Interface\DialogFrame\UI-DialogBox-Border">
		<BackgroundInsets>
			<AbsInset left="11" right="12" top="12" bottom="11"/>
		</BackgroundInsets>
		<EdgeSize>
			<AbsValue val="10"/>
		</EdgeSize>
        </Backdrop>
        <Anchors>
		<Anchor point="TOP">
			<Offset>
				<AbsDimension x="0" y="-500" />
			</Offset>
		</Anchor>
	</Anchors>
        <Scripts>
		<OnMouseDown>self:StartMoving();</OnMouseDown>
		<OnMouseUp>self:StopMovingOrSizing();</OnMouseUp>
		<OnDragStop>self:StopMovingOrSizing();</OnDragStop>
        </Scripts>
		<Frames>
			<Frame name="StatusGrp">
				<Size x="180" y="75" />
				<Backdrop edgeFile="Interface/Tooltips/UI-Tooltip-Border">
					<EdgeSize>
						<AbsValue val="10"/>
					</EdgeSize>
				</Backdrop>
				<Anchors>
					<Anchor point="TOP">
						<Offset>
							<AbsDimension x="0" y="-10" />
						</Offset>
					<Anchor>
				</Anchors>
			</frame>
		</Frames>
    </Frame>
Then I try to show the frame with the following code, and get an error saying it's a nil value

Code:
TrackerDialog:Show();
I feel like I'm missing something.

Last edited by Sweetsour : 12-05-15 at 03:36 PM.
  Reply With Quote
12-05-15, 03:45 PM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
You have the attribute virtual="true" set, which turns the frame into a template rather than an actual frame.
  Reply With Quote
12-05-15, 04:50 PM   #3
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Ah, good to know! Though, having done that, I'm still getting nothing to appear. Here's all the code that I have:

.TOC file
Code:
## Interface: 60200
## Title: Tracker
## Notes: <notes>
## Author: <name>
## Version: <versiom>

Core.lua
Tracker.xml
Tracker.xml
Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\..\FrameXML\UI.xsd">

	<Frame parent="UIParent" name="Tracker">
		<Anchors>
			<Anchor point="CENTER"/>
		</Anchors>
		<Scripts>
			<OnLoad>
				dTracker_OnLoad( self );
			</OnLoad>
			<OnEvent>
				Tracker_OnEvent( self, event, ... );
			</OnEvent>
		</Scripts>
	</Frame>

<!-- Dialog template -->
	<Frame name="Tracker_Dialog" hidden="false" frameStrata="DIALOG" parent="UIParent">
		<Size x="200" y="325"/>
		<Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background-Dark" edgeFile="Interface\DialogFrame\UI-DialogBox-Border">
			<BackgroundInsets>
				<AbsInset left="11" right="12" top="12" bottom="11"/>
			</BackgroundInsets>
			<EdgeSize>
				<AbsValue val="10"/>
			</EdgeSize>
		</Backdrop>
		<Anchors>
			<Anchor point="TOP">
				<Offset>
					<AbsDimension x="0" y="-500" />
				</Offset>
			</Anchor>
		</Anchors>
		<Scripts>
			<OnMouseDown>self:StartMoving();</OnMouseDown>
			<OnMouseUp>self:StopMovingOrSizing();</OnMouseUp>
			<OnDragStop>self:StopMovingOrSizing();</OnDragStop>
		</Scripts>
		<Frames>
			<Frame name="StatusGrp">
				<Size x="180" y="75" />
				<Backdrop edgeFile="Interface/Tooltips/UI-Tooltip-Border">
					<EdgeSize>
						<AbsValue val="10"/>
					</EdgeSize>
				</Backdrop>
				<Anchors>
					<Anchor point="TOP">
						<Offset>
							<AbsDimension x="0" y="-10" />
						</Offset>
					<Anchor>
				</Anchors>
			</frame>
		</Frames>
    </Frame>
</Ui>

Last edited by Sweetsour : 12-05-15 at 04:52 PM.
  Reply With Quote
12-05-15, 06:40 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Looks like you aren't closing your anchor tag for your StatusGrp frame and you have a lowercase </frame> instead of </Frame>
  Reply With Quote
12-05-15, 07:09 PM   #5
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
That was it! I also caught "<Size stuff /></Size>" and figured that may have caused some problems. Thanks for your help!
  Reply With Quote
12-09-15, 12:02 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Unless you really love XML and already have a workflow set up for writing XML (which it doesn't sound like you do) there's really no reason to use XML in a WoW addon (outside of a few specific advanced topics dealing with secure headers). Among other things, it makes debugging unnecessarily difficult. If you'd created your frame in Lua, you would have gotten a nice in-game error message telling you exactly what was wrong and where.

Also, regardless of whether you're using XML or not, you should avoid generic global frame and function names like "Tracker" and "Tracker_OnEvent". If they show up in a /framestack or an error message, there's no way to tell what addon they actually belong to, and you're just asking for your addon to get broken by some other addon (or by Blizzard) leaking a variable with the same generic name as a global, or for your addon to break the other addon (or the default UI) by overwriting its global.

General rules for using globals:

1. Don't do it unless you actually have to. This is another argument against XML, since it forces you to dump tons of stuff into the global namespace.

2. Make sure your global variables have unique names. "Tracker" is a bad frame name; "CoolRaidBuffTracker" or "SweetsourTracker" would be better choices.

3. Make sure your global variable names identify the addon that created them. As a happy coincidence, if your globals are prefixed with your addon's name, not only are they easily identifiable, but also much more likely to be unique.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » XML and Lua


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