why can't I refer to if it:getId() ~= 0 then
ItemType(id or name)
returns
ItemType
object, if parameter is
number
or
string
, otherwise it returns
nil
.
It means that in 13 line of
Timur.lua
you try to add some item using
addSellableItem
, but value passed as ID is not a number/string.
Your value is probably
table
or
nil
:
table
in case your parameters are in wrong order and you passed 'item names list' as id/name of item
nil
in case you use variable as item ID and this variable is not defined
Valid code from TFS 1.4:
LUA:
shopModule:addSellableItem({'empty potion flask', 'empty flask'}, 7636, 5, 'empty small potion flask')
Code that passes
table
as item ID/name, because I added 1 parameter at start, so list of item names is 2nd parameter now and script uses it as item ID/name:
LUA:
shopModule:addSellableItem('invalid parameter moves all next parameters to +1 position', {'empty potion flask', 'empty flask'}, 7636, 5, 'empty small potion flask')
Code that passes
nil
as item ID/name, because I replaced item ID
7636
with variable
notItemIdVariable
, but in code above I declared this ID as variable
itemId
, so
notItemIdVariable
does not exist = is set to
nil
:
LUA:
local itemId = 7636
shopModule:addSellableItem({'empty potion flask', 'empty flask'}, notItemIdVariable, 5, 'empty small potion flask')
Your code with
if it == nil then
should detect these kinds of problems, but real problem is in
Timur.lua
.
Your code
if it == nil then
would also generate error in console, because it's bugged, but error would be different. Problem with your code is that
print
at end tries to concat
itemid
into string
print("[Warning (...)" .. itemid)
and you cannot concat string with
nil
or
table
and it will throw error. Safe code is to pass
itemid
as 2nd parameter to
print
, so it would be `
print("[Warning (...)", itemid)
. Then
itemid
will be processed by
print
as separate variable and it will be printed with TAB separator from warning message.
For future:
Often we can't help you without viewing your code. You posted some screenshot with some lines and with line numeration disabled. IDK which line is 916 on that screenshot. Next time post files that are reported in error, in this case:
data/npc/lib/npcsystem/modules.lua
and
data/npc/scripts/Timur.lua
.