如何跟踪基本的LUA错误?

我是LUA的初学者,所以遇到了一些麻烦。我正在使用一个名为Computercraft的Minecraft模组的代码,但对我来说它是入门编程的好材料。

我一直在搜索网络,想找出为什么我的代码只有不到26行,但失败了。但可惜的是我没有找到它。

代码如下:

monitor = peripheral.wrap("right")
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextScale(1)
monitor.print("当前模式:")
monitor.setCursorPos(1,3)
monitor.print("尘土去炉子里")
redstone.setOutput(back,false)
print("尘土自动运送到炉子里")
print("你想它去箱子里而不是炉子吗?")
write()
while input == ja
do
  print("好的:)")
  redstone.setOutput(back,true)
  monitor.clear()
  monitor.setCursorPos(1,1)
  monitor.print("当前模式:")
  monitor.setCursorPos(1,3)
  monitor.print("尘土去箱子里")
end
else
  print("好的,那就不去吧")
end

我知道我使用了‘end’两次。这是因为我删除一个时会出错。

当我运行程序时,我收到的错误是:

bios:14: [string ".temp"]:22: 预期‘<eof>’

当我删除第一个‘end’时收到的错误。

当我删除第二个‘end’时收到的错误。

编辑 好吧,经过一些建议,我设法摆脱了错误。 感谢所有回复的人!c: 现在我又出了一个错误lol。 如建议一样,我发布了一个新帖:Basic LUA problems

点赞
用户8373051
用户8373051

:22:告诉你出现了错误,发生在脚本的第22行,也就是else语句。如果你查看 Lua 参考手册,你会发现else是用于 if 语句的,而不是while语句。

你的代码应该像下面这样,因为在这里使用 while 没有意义:

if input == ja
then
  ... code ...
else
  ... other code ...
end
2017-08-26 00:46:10