我的LUA脚本中有一个problam,我正在尝试在MTA游戏服务器上创建一个新服务器,并在我的脚本中使用LUA Langauge,但我有一个控制台错误,不知道如何修复它< / p>
Consle错误
--The main function to open the entire advertisements system.
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
for _, ad in ipairs( exports.mysql:select('advertisements') ) 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.`
第117行错误: for _,ad in ipairs(exports.mysql:select('advertisements'))do
答案 0 :(得分:0)
试试这个。
database = dbConnect( "mysql", "dbname=databasename;host=1.2.3.4;charset=utf8", "username", "password" )
function getData()
local result = {}
local query = dbQuery(database, "select * from advertisements")
result = dbPoll(query,-1)
dbFree(query)
if #result > 0 then
return result
else
return {}
end
end
--The main function to open the entire advertisements system.
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
for _, ad in ipairs( getData() ) 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.`