Originally Posted by
Submann
No they are not defined by UICheckButtonTemplate, is UICheckButtonTemplate not just a standard "layout" or is it me there still don't get it ?
The UICheckButtonTemplate is a frame template which can have any number of properties defined that are then inherited by any frames that specify this template for creation - this includes script handlers. For example, SecureActionButtonTemplate and friends all define a secure OnClick handler in the template itself that allows them to perform secure operations (casting spells, using items, calling macros that do those).
Originally Posted by
Submann
but can't get the "GetText" to work, so i tryed with this
Code:
-- ********************* * * * * * Do your stuf * * * * * ********************
local GsGuild = CreateFrame("CheckButton", "SetGsGuild", Window, "UICheckButtonTemplate")
strText = "Text line here"
GsGuild:SetScript("OnEnter", OnEnter(strText));
GsGuild:SetScript("OnLeave", OnLeave);
GsGuild:SetPoint("TOPLEFT", Window, "TOPLEFT", 10, -30)
GsGuild.tooltip = "Tooltip here, now it's working ?";
if (GS_InGuild:lower() == "on") then
GsGuild:SetChecked(true)
else
GsGuild:SetChecked(false)
end
SetGsGuildText:SetText(strText);
GsGuild:SetScript("OnClick", function()
if (GsGuild:GetChecked() == 1) then
GS_InGuild = "on"
elseif (GsGuild:GetChecked() == nil) then
GS_InGuild = "off"
else
print("Error");
end
end)
end
function OnEnter(self, strText)
GameTooltip:ClearLines()
GameTooltip:SetOwner(self,"ANCHOR_RIGHT")
GameTooltip:AddLine(strText,1,0.82,0)
GameTooltip:AddLine(self.tooltip,1,1,1)
GameTooltip:Show()
end
But the "GetText" is it still not working, any ide how to make it work ?
This one has a different issue in that you're misunderstanding how :SetScript calls work.
What you do when you call SetScript is you pass the frame as arg1 (done through the colon call automatically), you pass the script handler label as arg2, and then you pass a function reference as arg3 (every "function" is simply a pointer to a memory address that contains the code to be executed - tables also work this way).
Code:
GsGuild:SetScript("OnLeave", OnLeave);
Here you pass a reference to the function stored in variable OnLeave to the :SetScript call.
However, let's take a look at your other :SetScript line:
Code:
GsGuild:SetScript("OnEnter", OnEnter(strText));
Here you call the function stored in variable OnEnter with strText as arg1, then pass the return values of that function call to :SetScript. Now the solution I'd propose is to modify the :GetText call in OnEnter to read the proper FontString label for the button using :GetName to determine its global label (as determined by the UICheckButtonTemplate template to be $parentText - see my XML snippet from the template definition in my previous post).
Code:
local function OnEnter(self)
GameTooltip:ClearLines()
GameTooltip:SetOwner(self,"ANCHOR_RIGHT")
GameTooltip:AddLine(_G[self:GetName().."Text"]:GetText(),1,0.82,0)
GameTooltip:AddLine(self.tooltip,1,1,1)
GameTooltip:Show()
end
Revert the rest of your calls back to the way they were:
Code:
GsGuild:SetScript("OnEnter", OnEnter)
Code:
SetGsGuildText:SetText("Text line here")
PS: You might want to always double-check your code for whether you unnecessarily use the global namespace - your OnEnter and OnLeave definitions as well as the strText varaible both violate it. Proper etiquette would be to use locals (as you can see exemplified by my OnEnter definition above).
In case you're curious, this further ties in with the memory pointer handling of functions in Lua. Defining using "function" (in simple terms) creates a function object in memory from the function body, then saves a pointer to that memory location into a global variable with the name specified - "local function" on the other hand uses a local variable to store the function reference.
Hope this clears it up a bit!
PS: Make sure your functions (OnEnter and OnLeave) are defined before they are passed to SetScript.