Reputation: 21
when I try to use script function this error appears:
attempt to perform arithmetic on global 'amount' (a nil value)
this is the function:
<>
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 concerns this line:
for _, ad in ipairs( call(getResourceFromName("mysql"), "query_free", "UPDATE `accounts` SET `dm`=`dm`-".. amount*2000 .." WHERE `id`=".. tostring(gameAccountID) .."") ) do
Upvotes: 2
Views: 4293
Reputation: 1543
You haven't defined local amount
variable, so lua looks for it in global table (_ENV
or _G
, depending on lua version), where it doesn't exsist too (nil
for non-existing key).
Lua tries to exectue nil*2000
, which leads to that error.
Upvotes: 0