문제

I am calling an API function in the Lord of the Rings Online (LOTRO) Beta Lua scripting feature. The API method returns a "type" called ClassAttributes that will be on of the given Class Attribute "types". I say "types" because when I call type() on the return value, it says its a table.

Is there a way for me to check the type, or metatable type? e.g.:

local returnedTable = player:GetClassAttributes();

if (returnedTable.Name == "CaptainClassAttributes")
    print("You are playing a captain");
end

UPDATE The following code is what I use:

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

and here is the output:

player:GetClass():24
Turbine.Gameplay.Class.Captain:24
You are playing a captain

도움이 되었습니까?

해결책

The API docs are a bit confusing, although I suppose I found what you're looking for. The following code should tell you if player is a Captain:

local player = Turbine.Gameplay.Player
if (player:GetClass() == Turbine.Gameplay.Class.Captain) then
    print("You are playing a captain")
end

Captain is a member of the Gameplay.Class table, which is just an integer number as reading from the docs.

Note: You don't need to end a Lua sentence with a ";".

Couldn't test it. Hope it works.

다른 팁

If you have a list of the possible metatables for those values, you can get their metatables with the getmetatable(obj) function and compare them to the ones you already have. Without having access to the LOTRO API I can't say more about the subject: where can I read it?

That, of course, is assuming that the table returned by the GetClassAttributes() function has a metatable of itself, and that it is possible to differentiate between it's metatable and the other classes' attributes tables.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top