-
Posted by Drunk Cadaver on Tue, 09 Mar 2010 21:32:01
The mod I am working on has a basic frame that displays information. I would like to build a tooltip that displays more advanced information. I went thru chapter 24 in the book, and I've coded the tooltip. It works beautifully when I test it in WowLua. It attaches to my frame and displays just like I want. My problem is when I take the code from WowLua and try to make it show and hide in my mod, it doesn't show up and/or I get errors.
I have searched this site and a few others looking for examples or something to show me how it's done. I found a topic here that pretty much matched my question (lua newbie question). The code that was given as an example to help doesn't seem to work. I tested it in WowLua and even made it into a quick and easy mod.
This is the code provided:
local function OnEnter(self) GameTooltip:SetOwner(self, "ANCHOR_CURSOR") GameTooltip:SetText("tooltipTitle") GameTooltip:AddLine("This is the contents of my tooltip", 1, 1, 1) GameTooltip:Show() end local function OnLeave(self) GameTooltip:Hide() end local f = CreateFrame("Frame", nil, UIParent) f:SetFrameStrata("MEDIUM") f:SetWidth(50) f:SetHeight(50) f:SetScript("OnEnter", OnEnter) f:SetScript("OnLeave", OnLeave) local t = f:CreateTexture(nil, "BACKGROUND") t:SetTexture(1, 1, 1, 1) t:SetAllPoints(true) f.texture = t f:SetPoint("CENTER", 0, 0) f:Show()
It was missing a ")" after the frame was created and I made the box smaller. Aside from that the code is the same.
Can anyone help me? Thanks in advance.
-
Posted by jnwhiteh on Tue, 09 Mar 2010 22:27:12
Either make it a "Button" instead of a "Frame", or call f:EnableMouse(true). They changed the behaviour of frames somewhat (As compared to frames) and this should resolve your issue.
-
Posted by Drunk Cadaver on Tue, 09 Mar 2010 22:47:55
That worked when the LUA maked the frame. If my frame is created from the XML, how do I do customeFrame:SetScript("OnEnter", OnEnter) and customFrame:SetScript("OnLeave", OnLeave). When I run the mod, I get an error that says attempt to index a global 'customFrame' (a nil value).
-
Posted by jnwhiteh on Tue, 09 Mar 2010 22:59:58
In XML, you can do it right in a
<Scripts>
block.<Frame name="MyFrame" enableMouse="true"> <Scripts> <OnEnter> -- Write Lua code here -- You have access to self, etc. For example: print("Entering", self:GetName()) </OnEnter> <OnLeave> print("Leaving", self:GetName()) </OnLeave> </Scripts> </Frame>
-
Posted by Drunk Cadaver on Wed, 10 Mar 2010 00:03:16
Worked perfectly. Thanks!