LUA错误代码64:尝试索引字段“?”(一个空值)。
2012-11-3 1:56:36
收藏:0
阅读:140
评论:1
我一直得到这个代码弹出,但我不确定错误在哪里。有人可以帮帮我找出来吗?它说在第64行。抱歉我不知道如何将它放入代码中。这里是错误行的代码
if ( array[j][1] < smallest ) then
smallest = array[j][1]
index = j
end
--------- [ Element Data returns ] ---------
local function getData( theElement, key )
local key = tostring(key)
if isElement(theElement) and (key) then
return exports['[ars]anticheat-system']:c_callData( theElement, tostring(key) )
else
return false
end
end
-------------- [ Scoreboard ] ---------------
local screenX, screenY = guiGetScreenSize()
local width, height = 300, 420
local x = (screenX/2) - (width/2)
local y = (screenY/2) - (height/2)
local logowidth, logoheight = 275, 275
local logox = (x/2) - (logowidth/2)
local logoy = (y/2) - (logoheight/2)
local isEventHandled = false
local page = 1
local a = { "Z", "W", "Y", "G", "H", "L", "P", "A", "B" }
function getPlayerIDTable( )
local array = { }
for key, thePlayer in ipairs ( getElementsByType("player") ) do
local playerID = tonumber( getData( thePlayer, "playerid") )
if ( playerID ) then
array[#array + 1] = { playerID, thePlayer }
end
end
for i = 1, 9 do
local j = math.random( 1, 9 )
if ( array[i] == nil ) then
array[i] = { j, a[ math.random( 1, 9 ) ] }
end
end
return array
end
local players = { }
function assemblePlayersByID( )
local array = getPlayerIDTable( )
local smallest, index, tempo
for i = 1, #array do
smallest = array[i][1]
index = i
for j = i + 1, #array do
if ( array[j][1] < smallest ) then
smallest = array[j][1]
index = j
end
end
-- flip arrays
tempo = array[i]
array[i] = array[index]
array[index] = tempo
end
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
该错误意味着您正在尝试索引一个空值。
假设“第64行”是您发布的代码中的第一行:
if(array[j][1]<smallest) then这意味着
array[j]为空:换句话说,在您的数组中没有索引j的值。您可以像这样检查它:if array[j] and array[j][1] and array[j][1] < smallest then请注意,您必须同时测试
array[j]和array[j][1],因为如果array[j]存在但array[j][1]不存在,则<比较将导致“尝试将nil与数字比较”的错误。