魔兽世界界面插件 - 隐藏和显示按钮

我正在编写一个简单的界面插件来为《魔兽世界》添加一些功能,但遇到了些问题。我想实现以下功能:如果我的某个技能没有冷却时间,就显示一个按钮。如果我点击按钮,则会施放该技能,在冷却时间内隐藏按钮。

施法部分工作得很好,但我遇到了隐藏按钮的问题。每次点击后都会在聊天界面中得到一个错误消息。这是我的代码:

TestAddon.toc

## Interface: 60000
## Title: TestAddon
## Notes: Test
## Version: 1.0
TestAddon.lua

TestAddon.lua

btn_schutz = CreateFrame("Button", "MyButton", UIParent, "SecureActionButtonTemplate");
btn_schutz:ClearAllPoints();
btn_schutz:SetAttribute("type", "spell");
btn_schutz:SetAttribute("spell", "Schutz"); -- Schutz是技能名称(德语)
btn_schutz:SetAttribute("unit", "player");
btn_schutz:SetPoint("CENTER", 0, 0);
btn_schutz:SetNormalTexture("Interface\\Icons\\ability_monk_guard");
btn_schutz:SetSize(48, 48);
btn_schutz:SetScript("OnUpdate", onUpdate);
btn_schutz:Show();

function onUpdate()
    local schutz_id = 115295;
    if GetSpellCooldown(schutz_id) == 0 then
        btn_schutz:Show(); -- 导致错误消息
    else
        btn_schutz:Hide(); -- 导致错误消息
    end
end
点赞
用户1068128
用户1068128

看起来你遇到了标准的污染错误。在这里阅读更多信息:安全执行和污染

当你的角色正在战斗中时,你无法显示或隐藏按钮(或任何“安全”框架)。

2014-10-28 17:52:29