Thread Tools Display Modes
10-22-10, 05:51 PM   #1
Toragon
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jan 2009
Posts: 11
My button not saving the id

Can someone help me

I cannot figure out why the self:GetID() is return nil in Amf.ActionButton_OnLoad (self)
I set the id in Amf.ActionButton_CreateButton(state,index) and the Amf.defualts.totalButtons is returning the right value.


Code:

function Amf.ActionButton_CreateButton(state,index)
	local button
	button = CreateFrame("CheckButton", "ActionButton"..state .."_"..index, _G["MainBarFrame"], "AmfBarButtonTemplate")
	Amf.defualts.totalButtons = (Amf.defualts.totalButtons + 1)
	button:SetID(Amf.defualts.totalButtons)
	return button
end


function Amf.ActionButton_OnLoad (self)
	

	self.action = self:GetID()
	self.flashing = 0;
	self.flashtime = 0;
	self:SetAttribute("showgrid", 0);
	self:SetAttribute("type", "action");
	self:SetAttribute("checkselfcast", true);
	self:SetAttribute("checkfocuscast", true);
	self:RegisterForDrag("LeftButton", "RightButton");
	self:RegisterForClicks("AnyDown");
	self:RegisterEvent("PLAYER_ENTERING_WORLD");
	self:RegisterEvent("ACTIONBAR_SHOWGRID");
	self:RegisterEvent("ACTIONBAR_HIDEGRID");
	self:RegisterEvent("ACTIONBAR_PAGE_CHANGED");
	self:RegisterEvent("ACTIONBAR_SLOT_CHANGED");
	Amf.ActionButton_Update (self)
	Amf.ActionButton_UpdateHotkeys(self, self.buttonType);
	
end
  Reply With Quote
10-22-10, 06:02 PM   #2
adracamas
A Fallenroot Satyr
 
adracamas's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 28
looks like your missing a ; at the end of it... also, is this in need of a (local) prefix?
__________________
--
"Our endless maniacal appetites left us with another way to die." -- Disturbed
  Reply With Quote
10-22-10, 06:43 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
What does the XML code look like for AmfBarButtonTemplate?
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-22-10, 06:56 PM   #4
Toragon
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jan 2009
Posts: 11
Here is my 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">

	<CheckButton name="AmfBarButtonTemplate" inherits="SecureActionButtonTemplate, ActionButtonTemplate" virtual="true">
			<Scripts>
			<OnLoad>
				Amf.ActionButton_OnLoad(self);
			</OnLoad> 
			<OnAttributeChanged>
			</OnAttributeChanged>
			<OnEvent>
				Amf.ActionButton_OnEvent(self, event, ...);
			</OnEvent>
			<PostClick>
				Amf.ActionButton_UpdateState(self, button, down);
			</PostClick>
			<OnDragStart>
				if ( LOCK_ACTIONBAR ~= "1" or IsModifiedClick("PICKUPACTION") ) then
					SpellFlyout:Hide();
					PickupAction(self.action);
					Amf.ActionButton_UpdateState(self);
					Amf.ActionButton_UpdateFlash(self);
				end
			</OnDragStart>
			<OnReceiveDrag>
				
				PlaceAction(self.action);
				Amf.ActionButton_UpdateState(self);
				Amf.ActionButton_UpdateFlash(self);
			</OnReceiveDrag>
			<OnEnter>
				Amf.ActionButton_SetTooltip(self);
				Amf.ActionButton_UpdateFlyout(self);
			</OnEnter>
			<OnLeave>
				GameTooltip:Hide();
				Amf.ActionButton_UpdateFlyout(self);
			</OnLeave>
			<OnUpdate>
				Amf.ActionButton_OnUpdate(self, elapsed);
			</OnUpdate>
		</Scripts>
	</CheckButton>
	<Frame name="MainBarFrame" parent="UIParent" inherits="SecureHandlerStateTemplate">
	<Size x="315" y="185"/>
	<Anchors>
		<Anchor point="CENTER"/>
	</Anchors>
  <Backdrop bgFile="Interface\TutorialFrame\TutorialFrameBackground" tile="true">
	<EdgeSize>
		<AbsValue val="16"/>
	</EdgeSize>
	<TileSize>
		<AbsValue val="32"/>
	</TileSize>
	<BackgroundInsets>
		<AbsInset left="5" right="5" top="5" bottom="5"/>
	</BackgroundInsets>
  </Backdrop>
  <Attributes>
	<Attribute name="state" value=" control:ChildUpdate('state', newstate)" />
  </Attributes>
	<Frames>
			<CheckButton name="AmfUpArrow" inherits="ActionButtonTemplate">
				<Anchors>
					<Anchor point="TOP"  relativePoint="TOP">
						<Offset>
							<AbsDimension x="6" y="0"/>
						</Offset>
					</Anchor>
				</Anchors>
				<NormalTexture file="Interface\ICONS\misc_arrowlup"/>
				<PushedTexture file="Interface\ICONS\misc_arrowlup"/>
			</CheckButton>
			<CheckButton name="AmfDownArrow" inherits="ActionButtonTemplate">
				<Anchors>
					<Anchor point="TOP" relativeTo="AmfUpArrow" relativePoint="BOTTOM">
						<Offset>
							<AbsDimension x="0" y="-6"/>
						</Offset>
					</Anchor>
				</Anchors>
				<NormalTexture file="Interface\ICONS\misc_arrowdown"/>
				<PushedTexture file="Interface\ICONS\misc_arrowdown"/>
			</CheckButton>
			<CheckButton name="AmfLeftArrow" inherits="ActionButtonTemplate">
				<Anchors>
					<Anchor point="RIGHT" relativeTo="AmfDownArrow" relativePoint="LEFT">
						<Offset>
							<AbsDimension x="-6" y="0"/>
						</Offset>
					</Anchor>
				</Anchors>
				<NormalTexture file="Interface\ICONS\misc_arrowleft"/>
				<PushedTexture file="Interface\ICONS\misc_arrowleft"/>
			</CheckButton>
			<CheckButton name="AmfRightArrow" inherits="ActionButtonTemplate">
				<Anchors>
					<Anchor point="LEFT" relativeTo="AmfDownArrow" relativePoint="RIGHT">
						<Offset>
							<AbsDimension x="6" y="0"/>
						</Offset>
					</Anchor>
				</Anchors>
				<NormalTexture file="Interface\ICONS\misc_arrowright"/>
				<PushedTexture file="Interface\ICONS\misc_arrowright"/>
			</CheckButton>			
		</Frames>	
        </Frame>
</Ui>
  Reply With Quote
10-22-10, 07:33 PM   #5
Toragon
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jan 2009
Posts: 11
Thank, I think I figured it out. self.action = self:GetID() is called before button:setID().
  Reply With Quote
10-22-10, 09:32 PM   #6
Taroven
A Cyclonian
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 49
I really do feel the need to nitpick.
Example:
Code:
local foo = function (bar)
    OHaiThar()
    TheseDontNeedSemicolons()
end

local foo = function (bar)
    OHaiThar(); ThisIsWhatSemicolonsAreUsedFor()
end
Hopefully that makes your future coding efforts a little less aggravating. In most cases you should never really feel the need for a semicolon in Lua. They're pretty much newlines without the newline.
__________________
Former author of EventHorizon Continued and Other Releases.
  Reply With Quote
10-22-10, 11:43 PM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Most programming languages require a token delimiter and counts newlines as whitespace. Lua is one of those that isn't strict on that policy, but it's still a good idea to follow it.

As far as the OnLoad handler, that code does run immediately after CreateFrame as part of that function call. Adding a note, if creating a frame in Lua that doesn't inherit an OnLoad handler, defining one later in code does not run it since the object has already loaded. Just a tip on the subject.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » My button not saving the id


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