error-handling - LUA 错误我想不通

标签 error-handling lua

This is the error

[ERROR] gamemodes/taloslife/gamemode/cl_networking.lua:99: attempt to index a nil value

This is the file:

由于最大字长无法添加,但这是 99 所在的代码块
function GM.Net:GetProtocolIDByName( strProtocol )
    return self.m_tblProtocols.Names[strProtocol].ID
end

我真的无法弄清楚这有什么问题,如果有人能告诉我修复方法,将不胜感激。我花了几个小时研究这个问题,但找不到解决办法。

最佳答案

当您读取 Names 表中不存在的内容时,您将得到 nil。

return self.m_tblProtocols.Names[strProtocol].ID



然后你试图从 nil 值中获取 ID 字段,所以你得到这个“尝试索引 nil”错误。

首先检查协议(protocol)名称是否保存在该表中。

关于error-handling - LUA 错误我想不通,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37492657/

相关文章:

c - 修改后的lua : Lua_close freezes in pthread

json - 将 json 文件与变量连接

lua - 为什么 0.575 * 100 与 57.5 不同?

oop - Love2D(Lua)中的面向对象编程

javascript 函数回调,参数(错误、响应、正文)顺序重要吗?

node.js - 使用 MongoDB 删除 Node.js 中上传的文件

haskell - 在Haskell中使用ErrorT

Lua 脚本 - 在字符串中查找数字

android - Android + Google API v2

go - `Exit(1)` 到哪里,哪里返回错误?