Thread Tools Display Modes
01-29-15, 11:13 AM   #1
odjur84
A Fallenroot Satyr
 
odjur84's Avatar
Join Date: Jan 2015
Posts: 24
XML problem: Twice function call

Hi!

I'm new to addon programming and currently coding a LootCouncil-Addon for my guild. But as I said, I'm new to Lua and XML (not to programming in general) and since I've desperately tried to figure out what is wrong with my code, I've decided to ask people, who are more familiar with that. As english isn't my mother tongue, please forgive me my probably bad spelling.

I have two addons, that consist of the same .lua-file with the exact identical code:

Code:
local frame = CreateFrame("FRAME", "FooAddonFrame");
frame:RegisterEvent("PLAYER_ENTERING_WORLD");
frame:RegisterEvent("LOOT_OPENED");

local function eventHandler(self, event, ...)
 if (event == "PLAYER_ENTERING_WORLD") then
	print("Hello!");
 end
 if (event == "LOOT_OPENED") then
	local texture, lootname, quantity, quality, locked = GetLootSlotInfo(1);
	print("You've found " .. lootname .. "!");
 end
end

frame:SetScript("OnEvent", eventHandler);

function Button1_OnClick()
	Frame1:Hide();
end
Then I have two XML-files, that are fairly different, because one of them is only a "test-XML-file" and the other my WIP-addon-file. What I want to do: Whenever a player opens a loot table (Event LOOT_OPENED is fired) the first item of the loot table should be printed in the chat window. This works just perfectly with my test-addon, consisting of the mentioned .lua-file and the following (basic) XML-file:

Code:
<Ui xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.blizzard.com/wow/ui/">
	<Script file="Frame.lua" />
	<Frame name="Frame1" parent="UIParent" toplevel="true" movable="true" enableMouse="true">
		<Size>
			<AbsDimension x="184" y="96" />
		</Size>
		<Anchors>
			<Anchor point="CENTER">
				<Offset x="-8" y="52" />
			</Anchor>
		</Anchors>
		<Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
			<BackgroundInsets>
				<AbsInset left="11" right="12" top="12" bottom="11" />
			</BackgroundInsets>
			<TileSize>
				<AbsValue val="32" />
			</TileSize>
			<EdgeSize>
				<AbsValue val="32" />
			</EdgeSize>
		</Backdrop>
		<Frames>
			<Button name="Button1" inherits="UIPanelButtonTemplate" text="Button1">
				<Size>
					<AbsDimension x="75" y="23" />
				</Size>
				<Anchors>
					<Anchor point="TOPLEFT">
						<Offset x="50" y="-57" />
					</Anchor>
				</Anchors>
				<Scripts>
					<OnClick>Button1_OnClick();</OnClick>
				</Scripts>
			</Button>
		</Frames>
		<Layers>
			<Layer level="OVERLAY">
				<FontString name="FontString1" inherits="GameFontNormal" text="Hello, World!">
					<Size>
						<AbsDimension x="80" y="20" />
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT">
							<Offset x="50" y="-12" />
						</Anchor>
					</Anchors>
				</FontString>
			</Layer>
		</Layers>
	</Frame>
</Ui>
But it doesn't work with the other (bigger and more complicated) XML-file. And I've really desperately tried everything to solve the problem, but I don't get it. Everytime I use the WIP-addon-file, he prints the item twice in the chat! Here's it:

Code:
<Ui xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.blizzard.com/wow/ui/">
	<Script file="Frame.lua" />
	<Frame name="ORC_FrameUser" hidden="true" parent="UIParent" toplevel="true" movable="true" enableMouse="true">
		<Size>
			<AbsDimension x="514" y="514" />
		</Size>
		<Anchors>
			<Anchor point="CENTER">
				<Offset x="-6" y="-32" />
			</Anchor>
		</Anchors>
		<Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
			<BackgroundInsets>
				<AbsInset left="11" right="12" top="12" bottom="11" />
			</BackgroundInsets>
			<TileSize>
				<AbsValue val="32" />
			</TileSize>
			<EdgeSize>
				<AbsValue val="32" />
			</EdgeSize>
		</Backdrop>
		<Frames>
			<Button name="ORC_UserSettings" inherits="UIPanelButtonTemplate" id="2" text="Settings">
				<Size>
					<AbsDimension x="75" y="23" />
				</Size>
				<Anchors>
					<Anchor point="TOPLEFT">
						<Offset x="416" y="-17" />
					</Anchor>
				</Anchors>
				<Scripts>
					<OnClick>ORC_UserSettings_OnClick();</OnClick>
				</Scripts>
			</Button>
			<Button name="ORC_UserNeed1" inherits="UIPanelButtonTemplate" id="5" text="Need">
				<Size>
					<AbsDimension x="64" y="23" />
				</Size>
				<Anchors>
					<Anchor point="TOPLEFT">
						<Offset x="39" y="-330" />
					</Anchor>
				</Anchors>
			</Button>
			<Button name="ORC_UserUpdate1" inherits="UIPanelButtonTemplate" id="6" text="Kl. Update">
				<Size>
					<AbsDimension x="64" y="23" />
				</Size>
				<Anchors>
					<Anchor point="TOPLEFT">
						<Offset x="38" y="-359" />
					</Anchor>
				</Anchors>
				<Scripts>
					<OnClick>ORC_UserUpdate_OnClick();</OnClick>
				</Scripts>
			</Button>
			<Button name="ORC_Button2nd1" inherits="UIPanelButtonTemplate" id="7" text="2nd">
				<Size>
					<AbsDimension x="64" y="23" />
				</Size>
				<Anchors>
					<Anchor point="TOPLEFT">
						<Offset x="38" y="-389" />
					</Anchor>
				</Anchors>
			</Button>
			<Button name="ORC_UserTransmogg1" inherits="UIPanelButtonTemplate" id="8" text="Transm.">
				<Size>
					<AbsDimension x="64" y="23" />
				</Size>
				<Anchors>
					<Anchor point="TOPLEFT">
						<Offset x="38" y="-419" />
					</Anchor>
				</Anchors>
			</Button>
			<Button name="ORC_UserPass" inherits="UIPanelButtonTemplate" id="4" text="Passen">
				<Size>
					<AbsDimension x="64" y="23" />
				</Size>
				<Anchors>
					<Anchor point="TOPLEFT">
						<Offset x="39" y="-301" />
					</Anchor>
				</Anchors>
				<Scripts>
					<OnClick>ORC_UserPass_OnClick();</OnClick>
				</Scripts>
			</Button>
			<Button name="ORC_UserClose" inherits="UIPanelButtonTemplate" id="1" text="Schließen">
				<Size>
					<AbsDimension x="75" y="23" />
				</Size>
				<Anchors>
					<Anchor point="TOPLEFT">
						<Offset x="233" y="-477" />
					</Anchor>
				</Anchors>
				<Scripts>
					<OnClick>ORC_UserClose_OnClick();</OnClick>
				</Scripts>
			</Button>
		</Frames>
		<Layers>
			<Layer level="OVERLAY">
				<FontString name="FontString1" inherits="GameFontNormal" text="Name:" justifyH="LEFT">
					<Size>
						<AbsDimension x="80" y="20" />
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT">
							<Offset x="12" y="-20" />
						</Anchor>
					</Anchors>
				</FontString>
				<FontString name="ORC_UserName" inherits="GameFontNormal" text="Name" justifyH="LEFT">
					<Size>
						<AbsDimension x="297" y="20" />
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT">
							<Offset x="112" y="-20" />
						</Anchor>
					</Anchors>
				</FontString>
				<FontString name="FontString2" inherits="GameFontNormal" text="Klasse:" justifyH="LEFT">
					<Size>
						<AbsDimension x="80" y="20" />
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT">
							<Offset x="12" y="-46" />
						</Anchor>
					</Anchors>
				</FontString>
				<FontString name="ORC_UserClass" inherits="GameFontNormal" text="Class" justifyH="LEFT">
					<Size>
						<AbsDimension x="297" y="20" />
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT">
							<Offset x="112" y="-45" />
						</Anchor>
					</Anchors>
				</FontString>
				<FontString name="Specc:" inherits="GameFontNormal" text="Specc:" justifyH="LEFT">
					<Size>
						<AbsDimension x="80" y="20" />
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT">
							<Offset x="12" y="-72" />
						</Anchor>
					</Anchors>
				</FontString>
				<FontString name="ORC_UserSpecc" inherits="GameFontNormal" text="Specc" justifyH="LEFT">
					<Size>
						<AbsDimension x="297" y="20" />
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT">
							<Offset x="112" y="-72" />
						</Anchor>
					</Anchors>
				</FontString>
				<FontString name="FontString3" inherits="GameFontNormal" text="Stat-Prio:" justifyH="LEFT">
					<Size>
						<AbsDimension x="80" y="20" />
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT">
							<Offset x="12" y="-112" />
						</Anchor>
					</Anchors>
				</FontString>
				<FontString name="ORC_UserStatprio" inherits="GameFontNormal" text="Duxensteinigkeit &gt; Bärtigkeit = STFU = kackamannistdoof" justifyV="TOP" justifyH="LEFT">
					<Size>
						<AbsDimension x="474" y="60" />
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT">
							<Offset x="12" y="-139" />
						</Anchor>
					</Anchors>
				</FontString>
			</Layer>
		</Layers>
	</Frame>
</Ui>
Can anyone help me please? I'm totally confused. I bet it's just a simple detail, but I don't get it.

Sincerly yours

odjur84
  Reply With Quote
01-29-15, 11:15 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Check your toc file. Make sure your script is loaded in XML-File OR toc ... not in both.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
01-29-15, 11:23 AM   #3
odjur84
A Fallenroot Satyr
 
odjur84's Avatar
Join Date: Jan 2015
Posts: 24
Arg, I'm feeling so stupid.

Thank you very much! That did the trick. And I tought "no need to check the TOC-file.. what can go wrong with 3 lines?"
  Reply With Quote
01-29-15, 12:55 PM   #4
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
This is only the first trap when using xml I'd recommend to not use XML at all.
Lua can do most things that are needed without any XML.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
01-29-15, 02:18 PM   #5
odjur84
A Fallenroot Satyr
 
odjur84's Avatar
Join Date: Jan 2015
Posts: 24
Do you mean creating the XML-elements of the interface by using lua-code instead of using a separate XML-file? Or how do you create an interface without using XML at all?
  Reply With Quote
01-29-15, 02:26 PM   #6
Banknorris
A Chromatic Dragonspawn
 
Banknorris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 153
http://wow.gamepedia.com/Widget_API
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » XML problem: Twice function call


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