我在代码的一部分中有问题,我不是编码员,我在互联网上看了一下,但没有找到任何有帮助的问题,问题出在第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
答案 0 :(得分:0)
Lua仅接受从1开始的索引,当索引为0时,我通常会出现此错误。因此,您可以检查source
或Users[source].getGroup()
是否等于0,确保它们始终为{ {1}}。
答案 1 :(得分:0)
有点晚了,但供以后落入此处的其他人参考:
在类似
的日志中出现错误时 const userSchema = new mongoose.Schema({
username: {
type: String,
required: true,
immutable: true
}
});
这往往是因为从数据库中获取的数据为空。
例如
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'
中的第11行是:
esx_identity/server/main.lua
引用的if result[1].firstname ~= nil then
是从数据库返回的空值。 SQL查询通常非常接近问题代码行。
检查数据库中包含空值的行,然后删除或修复存在的空值。