我有一个问题在代码的一部分,我不是程序员,我在互联网上看了看,但我没有找到任何有用的东西,问题是在第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
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发布于 2018-08-20 22:52:18
Lua只接受从1开始的索引,当索引为0时,我通常会得到这个错误。因此,您可以检查source或Users[source].getGroup()是否可能等于0,确保它们始终为>= 1。
发布于 2019-06-30 23:18:24
有点晚了,但供其他在这里登陆的人参考:
当在日志中得到错误时,比如
citizen:/scripting/lua/scheduler.lua:351: server/main.lua:234: attempt to index a nil value (field '?')
这往往是因为从数据库获取的数据是空的。
例如,
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查询通常非常接近有问题的代码行。
检查数据库中是否有包含空值的行,并删除或修复任何存在的行。
https://stackoverflow.com/questions/51922296
复制相似问题