首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试索引nil值(字段'?')关于FiveM essentialmode

尝试索引nil值(字段'?')关于FiveM essentialmode
EN

Stack Overflow用户
提问于 2018-08-20 06:22:25
回答 2查看 27.1K关注 0票数 0

我有一个问题在代码的一部分,我不是程序员,我在互联网上看了看,但我没有找到任何有用的东西,问题是在第234行,这是if groups[Users[source].getGroup()]:canTarget(group) then idk做什么,这是错误

Error running call reference function for resource essentialmode: citizen:/scripting/lua/scheduler.lua:351: server/main.lua:234: attempt to index a nil value (field '?') stack traceback: server/main.lua:234: in upvalue 'ref' citizen:/scripting/lua/scheduler.lua:337: in function citizen:/scripting/lua/scheduler.lua:336 [C]: in function 'xpcall' citizen:/scripting/lua/scheduler.lua:336: in function citizen:/scripcfx ting/lua/scheduler.lua:335> stack traceback: [C]: in function 'error' citizen:/scripting/lua/scheduler.lua:351: in function citizen:/scripting/lua/scheduler.lua:322

代码语言:javascript
复制
function addGroupCommand(command, group, callback, callbackfailed, suggestion)
commands[command] = {}
commands[command].perm = math.maxinteger
commands[command].group = group
commands[command].cmd = callback
commands[command].callbackfailed = callbackfailed

if suggestion then
    if not suggestion.params or not type(suggestion.params) == "table" then suggestion.params = {} end
    if not suggestion.help or not type(suggestion.help) == "string" then suggestion.help = "" end

    commandSuggestions[command] = suggestion
end

ExecuteCommand('add_ace group.' .. group .. ' command.' .. command .. ' allow')

RegisterCommand(command, function(source, args)
    if groups[Users[source].getGroup()]:canTarget(group) then
        callback(source, args, Users[source])
    else
        callbackfailed(source, args, Users[source])
    end
end)

debugMsg("Group command added: " .. command .. ", requires group: " .. group)          end
EN

回答 2

Stack Overflow用户

发布于 2018-08-20 22:52:18

Lua只接受从1开始的索引,当索引为0时,我通常会得到这个错误。因此,您可以检查sourceUsers[source].getGroup()是否可能等于0,确保它们始终为>= 1

票数 0
EN

Stack Overflow用户

发布于 2019-06-30 23:18:24

有点晚了,但供其他在这里登陆的人参考:

当在日志中得到错误时,比如

citizen:/scripting/lua/scheduler.lua:351: server/main.lua:234: attempt to index a nil value (field '?')

这往往是因为从数据库获取的数据是空的。

例如,

代码语言:javascript
复制
Error running call reference function for resource esx_identity: citizen:/scripting/lua/scheduler.lua:405: @esx_identity/server/main.lua:11: attempt to index a nil value (field '?')
stack traceback:
@esx_identity/server/main.lua:11: in upvalue 'ref'

esx_identity/server/main.lua中的第11行是:

if result[1].firstname ~= nil then

引用的firstname是从数据库返回的空值。SQL查询通常非常接近有问题的代码行。

检查数据库中是否有包含空值的行,并删除或修复任何存在的行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51922296

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档