【问题标题】:Lua Language MySQL: Error in my file, ipairsLua 语言 MySQL:我的文件中的错误,ipairs
【发布时间】:2017-08-18 21:20:45
【问题描述】:

我的 LUA 脚本有问题,我正在尝试在 MTA 游戏服务器上创建一个新服务器,并在我的脚本中使用 LUA 语言,但我有一个控制台错误,不知道如何修复它

控制台错误

File.lua 117 Line Error 和文件代码

--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 行错误: 对于 _,ipairs 中的广告(exports.mysql:select('advertisements'))做

【问题讨论】:

标签: mysql lua lua-table


【解决方案1】:

试试这个。

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.`

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-02
    • 2010-10-02
    • 2020-11-19
    • 2011-06-25
    • 2017-12-18
    • 2021-06-12
    • 2014-07-11
    • 2017-11-16
    相关资源
    最近更新 更多