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
基本LUA问题_Lua_Computercraft - Fatal编程技术网

基本LUA问题

基本LUA问题,lua,computercraft,Lua,Computercraft,我使用的是ComputerCraft,一个Minecraft mod,它添加了计算机、显示器、调制解调器等,可以使用Lua脚本编程 在运行脚本时,我遇到以下错误:“bios:171:错误参数:应为字符串,但为零” 我不明白,因为上面写着171行,即使我的代码不超过30行。。有人能解释一下吗 monitor = peripheral.wrap("right") monitor.clear() monitor.setCursorPos(1, 1) monitor.setTextScale(1) m

我使用的是ComputerCraft,一个Minecraft mod,它添加了计算机、显示器、调制解调器等,可以使用Lua脚本编程

在运行脚本时,我遇到以下错误:“bios:171:错误参数:应为字符串,但为零”

我不明白,因为上面写着171行,即使我的代码不超过30行。。有人能解释一下吗

monitor = peripheral.wrap("right")
monitor.clear()
monitor.setCursorPos(1, 1)
monitor.setTextScale(1)
monitor.write("Current mode:")
monitor.setCursorPos(1, 3)
monitor.write("furnace")
redstone.setOutput("back", false)
print("blablabla")
write()
if input == ja then
  print("k")
  redstone.setOutput("back", true)
  monitor.clear()
  monitor.setCursorPos(1, 1)
  monitor.write("blabla")
else
  print("u sux")
end

非常感谢您的帮助。

您在bios.lua中调用了一个错误,该错误实现了您可以在脚本中使用的功能。像

如果我们仔细研究一下,就会发现第171行实际上是
write
实现的一部分

它说:
while string.len(sText)>0 do
,其中
sText

是第154行中函数写入(sText)
的输入参数

对于
sText
nil
的情况,没有正确的错误处理或默认值。程序员在这里做得很草率

在这种情况下,第171行中的
string.len(sText)
将导致您收到的错误

为了解决这个问题,您必须删除对
write
的空调用,这相当于
write(nil)
,或者您必须提供一些输入字符串


write(“某物”)
不会导致任何错误。如果要打印空字符串,只需调用bios.lua中的一个错误,该错误实现了可以在脚本中使用的函数。像

如果我们仔细研究一下,就会发现第171行实际上是
write
实现的一部分

它说:
while string.len(sText)>0 do
,其中
sText

是第154行中函数写入(sText)
的输入参数

对于
sText
nil
的情况,没有正确的错误处理或默认值。程序员在这里做得很草率

在这种情况下,第171行中的
string.len(sText)
将导致您收到的错误

为了解决这个问题,您必须删除对
write
的空调用,这相当于
write(nil)
,或者您必须提供一些输入字符串


write(“某物”)
不会导致任何错误。如果你想打印一个空字符串,只需调用
write(“”)

我们不知道什么是“外围设备”是的,不知道
peripheral
几乎不可能猜测,但就像猜测
write()
看看这个command@JacekCz我们不知道什么是“外围”是的,如果不知道
外围设备
几乎不可能猜测,但就像猜测
write()
一样,看看这个command@JacekCz