我可以看到有人问过类似的问题,但是我对lua编码并不是很熟悉。我正在尝试修复旧的魔兽世界香草插件,以在Classic客户端中运行。
代码如下:
function FHH_OnLoad()
this:RegisterEvent("PLAYER_ENTERING_WORLD");
this:RegisterEvent("UPDATE_MOUSEOVER_UNIT");
-- Register Slash Commands
SLASH_FHH1 = "/huntershelper";
SLASH_FHH2 = "/hh";
SlashCmdList["FHH"] = function(msg)
FHH_ChatCommandHandler(msg);
end
local version = GetAddOnMetadata("GFW_HuntersHelper", "Version");
GFWUtils.Print("Fizzwidget Hunter's Helper "..version.." initialized!");
end
并且它引发以下错误;
Message: Interface\AddOns\GFW_HuntersHelper\HuntersHelper.lua:27: attempt to index global 'this' (a nil value)
Time: Tue Jun 30 09:25:14 2020
Count: 1
Stack: Interface\AddOns\GFW_HuntersHelper\HuntersHelper.lua:27: attempt to index global 'this' (a nil value)
Interface\AddOns\GFW_HuntersHelper\HuntersHelper.lua:27: in function `FHH_OnLoad'
[string "*:OnLoad"]:1: in function <[string "*:OnLoad"]:1>
Locals: (*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index global 'this' (a nil value)"
我已经尝试过使用“ this”语句,但是我不太确定该怎么做,以为我会看看你们中有没有聪明的人会知道发生了什么事
如果所涉及的插件太旧了,那么在过去的某个时候(2010年?),插件API已从全局变量移至局部变量。
框架在XML文件中定义,就像您在评论中发布的那样:
<Frame name="HuntersHelperFrame">
<Scripts>
<OnLoad>FHH_OnLoad();</OnLoad>
<OnEvent>
FHH_OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
</OnEvent>
</Scripts>
</Frame>
<Scripts>
实际上,其中的元素被称为函数,其内容为函数体。它们带有一些参数。您可以使用World of Warcraft API作为参考来找出哪些参数。它不是官方的,但这是参考手册中最接近的内容。
目前,您对Widget处理程序感兴趣。
现在,您应该采取的第一步是:
<Frame name="HuntersHelperFrame">
<Scripts>
<OnLoad>FHH_OnLoad(self)</OnLoad>
<OnEvent>
FHH_OnEvent(self, event, ...)
</OnEvent>
</Scripts>
</Frame>
function FHH_OnLoad(self)
self:RegisterEvent("PLAYER_ENTERING_WORLD")
-- and so on, change all occurrences of `this` to `self`
-- or simply name the first argument `this` instead of `self`:
-- function FHH_OnLoad(this)
end
-- Change all of the functions:
function FHH_OnEvent(self, event, ...)
-- function body
end
根据插件的大小,它可能会成为很大的工作。可悲的是,这还没有结束。请警惕,因为脚本可能直接依赖于全局变量的存在并执行一些技巧。
我猜您可以尝试使用local this = self
类似的技巧来解决它,但这可能不适用于所有情况,并且由于框架如何解析XML而可能会引起一些问题。
最后一点;这些年来,API发生了很大变化,您很可能会遇到更多问题。祝好运!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句