View Single Post
05/01/14, 01:41 AM   #1
arkemiffo
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 16
Dynamic buttons and function calls

Hello,

I'm in the process of building my first proper addon. the actual function of it is complete, all I need is to tie it in with the UI at the moment.
The addon is about mixture of ingredients for alchemy, so I have set up a loop to create virtual buttons, and they show up as they should. My problem however is that the handler of the buttons doesnt seem to work.
When I hardcoded the handler to a certain button I had no problems, but that kinda defeats the purpose of doing it in a loop.

The XML:
Code:
		<Button name="EffectButton" font="ZoFontGame" color="CFDCBD" mouseEnabled="true" 
			verticalAlignment="CENTER" horizontalAlignment="CENTER" virtual="true">
			<Dimensions x="200" y="30" />
			<Anchor point="TOPLEFT" />
			<Controls>
				<Backdrop name="$(parent)BG" inherits="ZO_ThinBackdrop" />
			</Controls>						
		</Button>
The lua:

Code:
local function NotebookInitialize(eventCode, addOnName)
	if(addOnName == "AlchemistsNotebook") then
		local counter = 0
		for columns = 1,2 do
			for rows = 1,6 do
				counter = counter + 1
				local EffectButtonControl = CreateControlFromVirtual("EffectButton", AlchemistsNotebook_ResultsBG, "EffectButton", counter)
				EffectButtonControl:SetText(antitrait_table[counter][1])
				EffectButtonControl:SetHandler("OnMouseDown", function(self) NotebookOnChange(counter) end)
				EffectButtonControl:SetSimpleAnchorParent(5+(200*(columns-1)),5+(30*(rows-1)))
			end
		end
	end
end
the buttons should be in 2 columns, with 6 buttons in each, that's why I have 2 for's.
The local var counter here is always 12 when actually pressing a button now. From all my years of programming other languages, it should hold the value it was during the iteration, but it seems it doesn't. Anyone that can help me?

(The counter binds into a table with the all the positive traits you can get from the ingredients, hence why it's so important to have it return the correct value).
  Reply With Quote