【发布时间】:2018-11-14 16:39:15
【问题描述】:
当我尝试使用脚本函数时出现此错误:
attempt to perform arithmetic on global 'amount' (a nil value)
这是函数:
<>
function openAdvertisements( player, command )
local advertisements = { } --These will hold our advertisements to send to the client and populate our advertisement tables.
if not player then player = source end
--Fetch all of the advertisements from the database --mysql:query("SELECT * FROM 'advertisements' WHERE 1")
for _, ad in ipairs( call(getResourceFromName("mysql"), "query_free", "UPDATE `accounts` SET `dm`=`dm`-".. amount*2000 .." WHERE `id`=".. tostring(gameAccountID) .."") ) do
if tonumber( ad.expiry ) >= tonumber( getRealTime().timestamp ) then --Check if the advertisement has expired, delete it if so.
ad.author = exports.mysql:select_one( "characters", { id = ad.created_by } ).charactername
table.insert( advertisements, ad )
else
deleteAdvertisement( ad.id )
end
end
triggerClientEvent( player, resourceName .. ":display_all", root, advertisements, exports.integration:isPlayerAdmin( player ) ) --Send the advertisements to the client to create the GUI.
end
ERROR 与这一行有关:
for _, ad in ipairs( call(getResourceFromName("mysql"), "query_free", "UPDATE `accounts` SET `dm`=`dm`-".. amount*2000 .." WHERE `id`=".. tostring(gameAccountID) .."") ) do
【问题讨论】:
-
变量
amount没有值,所以是nil,尝试计算nil*2000会报错,因为nil不是数字也不是可转换的字符串到一个数字。
标签: lua