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"); 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/"> 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/"> Sincerly yours odjur84 |
Check your toc file. Make sure your script is loaded in XML-File OR toc ... not in both.
|
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?" :D |
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. |
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?
|
|
For an example, here is how you would replicate your first (smaller) XML file in Lua alone:
Code:
local frame = CreateFrame("Frame", "MyAddonFrame", UIParent) -- [1] [1] The name value you provide when creating a frame is set as a global variable, and all addons (plus the default UI code) share the same global namespace. A global name like "Frame1" is bad for several reasons. First, it's likely to conflict with globals (intentional or otherwise) from other addons or the default UI. Second, when users are trying to figure out which addon a frame belongs to (for example, if they want to move the frame, they need to know where to look for options) just seeing "Frame1" in a /fstack tooltip doesn't help them. A better name would be something like "MyAddonFrame" where "MyAddon" is the name of your addon -- this is both helpful to users, and unlikely to conflict with anyone else's code. [2] object:SetSize(width, height) is shorthand for object:SetWidth(width) and object:SetHeight(height). [3] Typically only your main frame should have a global name, and its child frames and regions should not have global names. The exception to this rule is when inheriting from a Blizzard template that expects a name. However, the "UIPanelButtonTemplate" template doesn't expect a name (none of its child regions are named, and none of its scripts identify it or its child regions with :GetName() calls) this button doesn't need one. [4] Put the contents of the "Button1_OnClick" function here, and avoid such generic global function names in the future. The stuff in [1] applies equally to all globals, regardless of whether they're the names of frames, the names of functions, or anything else. [5] This will let you refer to "frame.button" later instead of needing the "local button" to be in scope or needing to do a global lookup on the button's name if it had one. If you're never going to do anything with the button from other parts of the code, you can just leave this line out. [6] Same as [5]. |
@Banknorris
Thanks for the links! I'll look it up soon! @Phanx Thanks to you also. I think, I will transform my XML-file into lua-only-code like you suggest in the final stage of my project. But before then I'll stick to the XML-files, simply because I think, that they offer a better visual landmark for me as a developer. When I have all the X- and Y-positions of all frame-elements, I can converse them easier to lua-only-code. :-) And also thank you for your additional notes, but note, that the first XML-file only was developed for testing, in the second (larger) file I mostly did use uncommon frame-names (like OCR_FrameUser). Nevertheless as from now I'm using 'nil' as names for most objects, thanks! |
In XML if you write "nil" as the value for the name attribute, that'll actually result in a global name of "nil" (a string) which isn't quite the same; to achieve the desired result (object without a name) just omit the entire attribute.
|
Hi!
Can you tell me how to omit the name if I want to have access to further arguments? Because Code:
newButton = CreateFrame("Button", , ORC_UserFrame); |
Quote:
Code:
newButton = CreateFrame("Button", nil, ORC_UserFrame); |
Well, as i understood Phanx, that it not equivalent to setting no name at all.
|
newButton = CreateFrame("Button", ORC_UserFrame);
CreateFrame can be called with one, two, tree, or four (five?) arguments and "decides" on the number of arguments how to handle them. Two arguments are handled as string/frame type and object/parent frame. Tree arguments are handled as string/frame type, string/frame Name, and object/parent frame The concept is called "function overloading" if you would like to dig into it. |
Quote:
|
Thanks to you two and especially to Duugu for the enlightenment!
|
Quote:
|
All times are GMT -6. The time now is 11:05 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI