1. greetings



    i am quite new to develop own addons and the few tutorials that are out there just let a few questions open. maybe you can help:



    i am trying to create a simple tooltip when mouse hovers a frame. i already got:

    Code:
    function showtooltip()

    local testtip = CreateFrame("GameTooltip", "ToolTipName") -- Where do i need the ToolTipName for example? Is it even neccessary to declare?

    testtip:SetFrameStrata("TOOLTIP")

    testtip:SetClampedToScreen(true)

    testtip:SetOwner(f, "ANCHOR_CURSOR")

    testtip:SetText("tooltipText", 1, 1, 1) -- Whats the difference between SetText and Addline?

    testtip:AddLine("tooltipText", 1, 1, 1)

    testtip:Show()

    end





    f = CreateFrame("Frame",nil,UIParent)

    f:SetFrameStrata("BACKGROUND")

    f:SetWidth(500)

    f:SetHeight(500)

    f:SetScript("OnEnter", showtooltip)



    t = f:CreateTexture(nil,"BACKGROUND")

    t:SetTexture(1, 1, 1, 1)

    t:SetAllPoints(f)

    f.texture = t



    f:SetPoint("CENTER",0,0)

    f:Show()

    the frame with the layer shows up ingame properly, but the tooltip hover isnt working. no error messages are shown.



    thnx for your help,



    peter

    greetings



    i am quite new to develop own addons and the few tutorials that are out there just let a few questions open. maybe you can help:



    i am trying to create a simple tooltip when mouse hovers a frame. i already got:

    Code:
    function showtooltip()

    local testtip = CreateFrame("GameTooltip", "ToolTipName") -- Where do i need the ToolTipName for example? Is it even neccessary to declare?

    testtip:SetFrameStrata("TOOLTIP")

    testtip:SetClampedToScreen(true)

    testtip:SetOwner(f, "ANCHOR_CURSOR")

    testtip:SetText("tooltipText", 1, 1, 1) -- Whats the difference between SetText and Addline?

    testtip:AddLine("tooltipText", 1, 1, 1)

    testtip:Show()

    end





    f = CreateFrame("Frame",nil,UIParent)

    f:SetFrameStrata("BACKGROUND")

    f:SetWidth(500)

    f:SetHeight(500)

    f:SetScript("OnEnter", showtooltip)



    t = f:CreateTexture(nil,"BACKGROUND")

    t:SetTexture(1, 1, 1, 1)

    t:SetAllPoints(f)

    f.texture = t



    f:SetPoint("CENTER",0,0)

    f:Show()

    the frame with the layer shows up ingame properly, but the tooltip hover isnt working. no error messages are shown.



    thnx for your help,



    peter

    It actually doesn't need to be that complex at all.  The following isn't tested, but should work. As for your questions:

    • You need to give the tooltip a name in order for you to be able to access the subframes (i.e. the individual lines of the tooltip).  You don't need to use the name anywhere, but certain types of frames should be named and this is one of them.  However, you don't need to create your own tooltip.. as a matter of fact I would suggest NOT doing that.  Just re-use what the game already has.
    • SetText() on a tooltip sets the top line of text, and can be used for  quick and dirty way of setting a single line.  AddLine adds a line to the tooltip, and takes in a color if necessary.
    • SetAllPoints() does NOT take a frame as an argument, it takes a boolean flag indicating true or false.  It will always set its points to match its parents when the value is true.  Luckily when you pass f, it counts as true in Lua.
    local function OnEnter(self)

    GameTooltip:SetOwner(self, "ANCHOR_CURSOR")

    GameTooltip:SetText("tooltipTitle") -- This sets the top line of text, in gold.

    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("BACKGROUND")

    f:SetWidth(500)

    f:SetHeight(500)

    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()