如何在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")

我正在为游戏《魔兽世界》开发插件,我想知道如何在print中改变字母的颜色

点赞
用户2858170
用户2858170

尝试这个。如果在一分钟内通过 Web 搜索找到了...

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

colors = {
    {
        title = 'LIGHTBLUE',
        color = 'cff00ccff',
    }, -- 还有更多
}
function printColors()
    --print("\124cffFF0000This text is red\124r") --这是红色
    local startLine = '\124'
    local endLine = '\124r'
    for i = 1, table.getn(colors) do
        print(startLine .. colors[i].color .. colors[i].title .. endLine)
    end
end

根据 https://wow.gamepedia.com/UI_escape_sequences,你还可以使用 WrapTextInColorCode(text, colorCode)

2021-03-15 07:15:01