Quantcast WoWInterface - View Single Post - Newbie LUA help with fontstrings
View Single Post
02-08-20, 01:16 PM   #1
save-disk
A Murloc Raider
Join Date: Feb 2020
Posts: 9
Newbie LUA help with fontstrings

Hi there! I'm not a programmer and don't really know any languages off by heart but have a basic grasp of how coding works, so excuse any silly oversights on my part. I just couldn't find the answer to my question after a week of combing through the wow API online so I thought I'd ask. I'm making an RP addon for myself that displays, after the character has stopped moving, whether you had run or walk toggled on (as other games have this and it's useful when you're roleplaying. At least, it's useful for me!)

I've managed to make it all work, but my text is appearing piled on top of each other instead of changing each time.

I assumed this was because I was accidentally creating a new font string each time instead of editing the old, but I can't find a 'delete text' function anywhere. Is this a thing? Sorry again for my dumb questions and thanks for your help!

Here is my full code:
Code:
frame = CreateFrame("Button", "frame", UIParent)


frame:RegisterEvent("PLAYER_STOPPED_MOVING");
local function eventHandler(self, event, ...)


            frame:SetWidth(120)
            frame:SetHeight(32)
            frame:SetToplevel(1)
            frame:SetFrameStrata("HIGH")
            frame:SetMovable(true)
            frame:EnableMouse(true)
            frame:RegisterForDrag("LeftButton")
            frame:RegisterForClicks("RightButtonUp")
            frame:SetPoint("TOP", Minimap, "BOTTOM", -150, 20)

            frame.Text = frame:CreateFontString("text", "OVERLAY", "GameFontNormal")

        
            frame.Text:SetJustifyH("CENTER")
            frame.Text:SetPoint("CENTER", 0, 0)

            frame:SetBackdrop({
                bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
                edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
                edgeSize = 16,
                insets = {left = 4, right = 4, top = 4, bottom = 4},
            })
            frame:SetBackdropColor(0,0,0,0.6)
            frame:SetBackdropBorderColor(1,0.8,0,0.8)  

local speed = GetUnitSpeed("player")
    if speed <= 6 then 
        frame.Text:SetText("Walking")
    elseif speed > 6 then
        frame.Text:SetText("Running")
    end
end
frame:SetScript("OnEvent", eventHandler);
  Reply With Quote