Jump to content
Alloder.pro  about Allods with love 😱
Search In
  • More options...
Find results that contain...
Find results in...

Servers monitoring and the Addons Editor

We present you two legends. All dreams come true.

Servers monitoring The Addons Editor

Digest April

We talk about what was done and updated in the past month. We help keep abreast of events.

Read more

Game tooltips

Tooltips provide a way for 3rd party fansites and extensions to display detailed information on mouseover.

Read more

Помогите. Param 1 not a class.


Guest kSky7000
 Share

Recommended Posts

Guest kSky7000

Привет! Нужна помощь.

Есть кусок кода:

Code:
function OnEventTargetChanged()

local targetId = avatar.GetTarget() or unit.GetPrimaryTarget( avatar.GetId() )

local Gibberling = unit.GetTrioInfo( targetId )

if not targetId or not Gibberling or not unit.IsPlayer( targetId ) then

wtMainPanel:Show( false )

return

end

local trio = unit.GetTrioInfo( targetId )

if trio then

--common.LogInfo( common.GetAddonName(), "Ник Второго: ", trio.name2, ", Ник третьего: ", trio.name3 )

wtNickText:SetVal( "value", trio.name2 )

wtNickkText:SetVal( "value", trio.name3 )

    end

wtMainPanel:Show( true )

end

В игре все работает идеально. Но если открыть лог файл mods.txt, то там постоянно появляется ошибка:

Code:
Error: addon Trio:   func: GetTrioInfo, field, line: -1, defined: C, line: -1,  [C] 

Error: addon Trio:     func: OnEventTargetChanged, global, line: 18, defined: Lua, line: 16,  [string "Mods/Addons/Trio/ScriptTrioInfo.lua"] 

Error: addon Trio: UI::LuaUnitGetTrioInfo: param 1 not a class GMUIHelper::ObjectId (type: nil), details: int __cdecl UI::LuaUnitGetTrioInfo(struct lua_State *) 

В lua я сильно не разбираюсь, поэтому прошу помочь. Объясните почему появляется ошибка и как от неё избавиться?

Link to comment
Share on other sites

Из доков:

Quote:
unit.GetTrioInfo( unitId )

-- параметры:

unitId: ObjectId ( not nil ) -- идентификатор игрока

Когда цели нет

Code:
targetId = nil
Следовательно
Code:
unit.GetTrioInfo( targetId )
вызовет ошибку. Избавиться от нее просто:

Code:
local Gibberling = targetId and unit.GetTrioInfo( targetId )
Link to comment
Share on other sites

а что вообще будет тогда когда and используется? - если там НИЛ то будет 2е значение? а если не НИЛ то первое? тоесть это аналогично:

Code:

local Gibberling

if targetId ~= nil then

    unit.GetTrioInfo( targetId )

else

   Gibberling = targetId

end

а если вместо and использовать or:

Code:
local Gibberling = targetId or unit.GetTrioInfo( targetId )
Link to comment
Share on other sites

Из документации по ЛУА

Quote:
Логические операции

В Lua это операции and , or , и not . Так же, как и в управляющих конструкциях (§2.4.4), все логические операции рассматривают false и nil как ложь , а все остальное как истину .

Операция отрицания not всегда возвращает false или true . Операция конъюнкции and возвращает свой первый параметр, если его значение false или nil ; в противном случае, and возвращает второй параметр. Оператор дизъюнкции or возвращает первый параметр, если его значение отлично от nil и false ; в противном случае, or возвращает второй параметр. И and и or вычисляют второй операнд только в случае необходимости. Примеры:

10 or 20 --> 10

10 or error() --> 10

nil or "a" --> "a"

nil and 10 --> nil

false and error() --> false

false and nil --> false

false or nil --> nil

10 and 20 --> 20

(В данном руководстве, --> указывает на результат предшествующего выражения.)

Короче, твое 1-е предположение верно, во 2-м вылезет ошибка, если targetId==nil ;)

Link to comment
Share on other sites

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

By using our site you agree to the Terms of Use