您可以比较LUA中的表格或Metatables的“类型”?
题
我在网上的指环王(Lotro)Beta Lua脚本功能中称为API功能。 API方法返回一个称为classAttributes的“类型”,该属性将在给定的类属性“类型”中。我说“类型”,因为当我打电话时 type()
关于返回值,它说它的桌子。
我有没有办法检查类型或MetaTable类型?例如:
local returnedTable = player:GetClassAttributes();
if (returnedTable.Name == "CaptainClassAttributes")
print("You are playing a captain");
end
更新以下代码是我使用的:
player = Turbine.Gameplay.LocalPlayer.GetInstance();
Turbine.Shell.WriteLine("player:GetClass():" .. player:GetClass());
Turbine.Shell.WriteLine("Turbine.Gameplay.Class.Captain:" .. Turbine.Gameplay.Class.Captain);
if (player:GetClass() == Turbine.Gameplay.Class.Captain) then
Turbine.Shell.WriteLine("You are playing a captain");
end
这是输出:
播放器:getClass():24
Turbine.gameplay.Class.Captain:24
你在扮演队长
解决方案
API文档有点令人困惑,尽管我想我找到了您想要的。以下代码应告诉您玩家是否是队长:
local player = Turbine.Gameplay.Player
if (player:GetClass() == Turbine.Gameplay.Class.Captain) then
print("You are playing a captain")
end
Captain是GamePlay.class表的成员,该表仅是文档读取的整数号码。
注意:您无需用“;”结束LUA句子。
无法测试。希望它有效。
其他提示
如果您有针对这些值的可能的分类列表,则可以使用 可获取(OBJ)功能 并将它们与您已经拥有的那些进行比较。如果不访问Lotro API,我无法对这个主题说更多:我可以在哪里阅读?
当然,这是假设由getClassAttributes()函数返回的表具有自身的计算,并且可以区分其MetaTable和其他类的属性表。
不隶属于 StackOverflow