luaworld-of-warcraft

How can i put color on text in lua?


currentHead, maximumHead= GetInventoryItemDurability(1);
currentShoulder, maximumShoulder = GetInventoryItemDurability(3);
currentChest, maximumChest = GetInventoryItemDurability(5);

print("Head: " .. currentHead .. " Durability")
print("Shoulders: " .. currentShoulder .. " Durability")
print("Chest: " .. currentChest .. "/" .. maximumChest .. " Durability")

I am making an addon for the game World of Warcraft , and i would like to know how can i change the color of the letters in print


Solution

  • Try this. If found it via websearch within a minute or so...

    https://www.wowinterface.com/forums/showthread.php?t=25712

    colors = {
        {
            title = 'LIGHTBLUE',
            color = 'cff00ccff',
        }, -- and many more
    }
    function printColors()
        --print("\124cffFF0000This text is red\124r") --This is red color
        local startLine = '\124'
        local endLine = '\124r'
        for i = 1, table.getn(colors) do
            print(startLine .. colors[i].color .. colors[i].title .. endLine)
        end
    end
    

    According to https://wow.gamepedia.com/UI_escape_sequences

    you can also use WrapTextInColorCode(text, colorCode)