View Single Post
07-04-12, 02:56 AM   #13
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by sigEleven View Post
I have supplied the code of calling the same function in two different ways, 1 via XML (code already provided), and 2 in lua (code already provided), which from my understanding, should have the same effect. Although, in my testing, they do not (the XML does not seem to call the function), so I was asking if anyone else could duplicate this, or provide an explanation.
Since this is neither the expected behavior of the WoW scripting environment, nor behavior observed by anyone else, the problem is obviously in some other part of your code, or maybe in how your code as a whole is structured. Without seeing it, though, we can't tell you. We can only tell you that there is nothing wrong with the tiny snippets you posted.

Originally Posted by sigEleven View Post
It seems ridiculous to me, that you want me to post the entirety of the code for this add-on (which is thousands of lines, over multiple files), in order to replicate the creation of a simple drop down menu. .... Also, you have not clearly stated what information you're looking for.
Again, that's because we have no idea what your code looks like. If we knew what was in your code and what to ask for, we would already be able to tell you where the problem is.

Originally Posted by sigEleven View Post
Flame on about the fact I didn't unallocate the memory for these variables when I was done with them.
If you're talking about the local info and items variables, you actually did deallocate the memory for them. Since they are inside a function, new instances of them are created each time you run the function, and are flagged for garbage collection (deallocation) at the end of the run since they are no longer in scope and are -- in the case of items whose value is a table, and thus passed by reference instead of value -- (presumably) not referenced anywhere else.

(On a side note, tables are fairly expensive to create in Lua, so you should aim to reuse them as much as possible. If the options table is static, it would be better to define it outside of the dropdown's initialize function. Maybe you're already doing this in your real code, but since we have no idea what your real code looks like, there's no way for us to know.)

Code:
<OnLoad>UNIQUEGLOBALFORTORHAL_MYFRAME12345_OnLoad</OnLoad>
This is not a valid call to the UNIQUEGLOBALFORTORHAL_MYFRAME12345_OnLoad function. Elsewhere in the code you just posted, you reference functions that are not defined, such as UNIQUEGLOBALFORTORHAL_MYBUTTON12345_OnClick.

Honestly, in the time you took to write all of that vague "example" code which does not actually help anyone figure out what's wrong with your code, you could have attached 100+ files to your post. I know you don't think it matters, and you seem to think your code is flawless and precious, but it really does matter. It may sound harsh, but if you can't figure out what the problem is and solve it yourself, what makes you think you can tell which parts of the code are relevant to debugging the problem?

As someone with a background in programming as something other than a hobby, you shouldn't be surprised or take it personally that other programmers want to see your code when you ask them why it isn't working the way you expect.

As far as the length or size of your code, of course nobody wants to read through 5,000,000 lines of code. That's not why we want you to post it. We want you to post it because the easiest way for us to help you -- especially with a large or complex addon -- is to load and debug your addon in-game, but without having the full, actual code, we can't do that.

--------------------

Finally, I loaded your "example" code in-game, with no other addons enabled, and was not able to reproduce the issue you described.

!!!Sandbox.toc
Code:
## Interface: 40300
Sandbox.xml
Sandbox.lua
Code:
-- Debug prints to see when "UIDropDownMenu_Initialize" is called for your dropdown:
hooksecurefunc("UIDropDownMenu_Initialize", function(frame, func)
	local name = frame:GetName()
	if name == "MYBUTTON12345" then
		print("UIDropDownMenu_Initialize", name)
	end
end)

function MYBUTTON12345_Initialize(self, level)
	-- Debug print to see when this function is called:
	print("MYBUTTON12345_Initialize")
	local info = UIDropDownMenu_CreateInfo()
	local items = {'Opt1', 'Opt2', 'Opt3'}
	for k,v in pairs(items) do
		info = UIDropDownMenu_CreateInfo()
		info.text = v
		info.value = v
		info.func = MYBUTTON12345_OnClick
		UIDropDownMenu_AddButton(info, level)
	end
end

function MYFRAME12345_OnLoad()
	-- Debug print to see when this function is called:
	print("MYFRAME12345_OnLoad")
	-- Comment or uncomment this line for testing:
	-- UIDropDownMenu_Initialize(MYBUTTON12345, MYBUTTON12345_Initialize)
end
Sandbox.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">
	<Script file="Sandbox.lua"/>
	<Frame name="MYFRAME12345">
		<Scripts>
			<OnLoad>
				-- Debug print to see when this script is executed:
				print("MYFRAME12345: OnLoad")
				MYFRAME12345_OnLoad(self)
			</OnLoad>
		</Scripts>
		<Frames>
			<Button name="MYBUTTON12345" inherits="UIDropDownMenuTemplate">
				<Scripts>
					<OnLoad>
						-- Debug print to see when this script is executed:
						print("MYBUTTON12345: OnLoad")
						-- Comment or uncomment this line for testing:
						UIDropDownMenu_Initialize(self, MYBUTTON12345_Initialize)
					</OnLoad>
				</Scripts>
			</Button>
		</Frames>
	</Frame>
</Ui>
The TOC calls only the XML file, and the XML file loads the Lua file before defining any frames, so all the functions defined in the Lua file are available to be called in scripts defined in the XML. Yes, I edited the global variables and comments to remove the unnecessary and inflammatory remarks. All other changes between the above and your posted code are either (a) syntax corrections so the code will load and function without errors, (b) additions of debug print statements, or (c) whitespace or indentation changes.

Results:

When UIDropDownMenu_Initialize is called from both MYFRAME12345_OnLoad and the button's XML OnLoad script:


When UIDropDownMenu_Initialize is called from only the button's XML OnLoad script:


When UIDropDownMenu_Initialize is called only from MYFRAME12345_OnLoad:


As you can see, UIDropDownMenu_Initialize is called and runs your MYBUTTON12345_Initialize function as expected in all three cases. (The order of debug messages for those two is actually the reverse of the order in which the functions are called, since the debug print for MYBUTTON12345_Initialize occurs at the beginning of the function, while the print for UIDropDownMenu_Initialize occurs after the entire function has run, since it's a secure post-hook.)

I feel I've already put in way more effort trying to help you than your posts and your attitude deserve. If you want more help, you really do need to post your actual code, not some "example" code that you obviously dry-coded because it's riddled with basic syntax errors and does not even illustrate the problem once those are fixed. You don't even have to copy and paste; you can simply scroll down on the posting page to the "Additional Options" section, click the "Manage Attachments" button, and attach your files to your post as-is.
__________________
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.

Last edited by Phanx : 07-04-12 at 02:58 AM.
  Reply With Quote