Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua “如何修复”;尝试索引一个nil值“;_Lua_Null_Minecraft_Opencomputers - Fatal编程技术网

Lua “如何修复”;尝试索引一个nil值“;

Lua “如何修复”;尝试索引一个nil值“;,lua,null,minecraft,opencomputers,Lua,Null,Minecraft,Opencomputers,我的代码有一个错误:它一直告诉我“尝试索引一个nil值(全局‘边’)” 我试图通过Minecraft(OpenComputers)学习Lua,但发现自己陷入了一个零值问题。可能有些东西不是来自Lua(国防部本身),但问题在于“纯Lua部分” component=require(“组件”) 事件=要求(“事件”) 计算机=需要(“计算机”) 期限=要求(“期限”) gpu=component.gpu 红石=组件。红石 gpu.setResolution(160,50) 尽管如此 术语.clear(

我的代码有一个错误:它一直告诉我“尝试索引一个nil值(全局‘边’)”

我试图通过Minecraft(OpenComputers)学习Lua,但发现自己陷入了一个零值问题。可能有些东西不是来自Lua(国防部本身),但问题在于“纯Lua部分”

component=require(“组件”)
事件=要求(“事件”)
计算机=需要(“计算机”)
期限=要求(“期限”)
gpu=component.gpu
红石=组件。红石
gpu.setResolution(160,50)
尽管如此
术语.clear()
术语集游标(1,1)
gpu.setBackground(0x5A5A)
gpu.set(1,1,“Allumer-lampe-Eteindre-lampe”)
术语集游标(1,2)
本地u,u,x,y=事件拉(“触摸”)
如果x>=2、x=19和x如上所述,则必须首先调用
require
,如以下代码段所示:

local component = require("component")
local sides = require("sides")
local rs = component.redstone
rs.setOutput(sides.back, rs.getInput(sides.left))

在您的代码中,没有定义边

正如你所说的:

redstone.setOutput(sides.left,15)
尝试使用索引操作符对侧面进行索引的位置

由于此范围内的
nil
值中的
sides
未知,因此无法为其编制索引。那没有道理

带有错误消息,Lua抱怨您的尝试

若要避免此错误,必须确保不索引nil值,或者在索引时确保它不是nil

sidesapi是一个可以在需要时加载的模块。 有一些代码在表中创建该API

local sides = require("sides")
将执行该代码并将对新创建的API表的引用存储在局部变量
sides

这样做之后,可以合法地索引
,因为
不再是
nil
,而是一个表


sides.left
将引用存储在表
sides
中的键
“left”

的值,因为它起作用了!谢谢分享解释,希望其他人也能理解
local sides = require("sides")