lua - 如何追踪基本的LUA错误?

标签 lua

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

我一直在网上搜索为什么我的不到 26 行的代码会失败,但遗憾的是我找不到它。

代码如下:

monitor = peripheral.wrap("right")
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextScale(1)
monitor.print("Current mode:")
monitor.setCursorPos(1,3)
monitor.print("Dust gaat naar furnace")
redstone.setOutput(back,false)
print("Dust gaat automatisch naar de furnace toe")
print("Wil je dat de dust naar de chest gaat in plaats van de furnace?")
write()
while input == ja
do
  print("Oke :)")
  redstone.setOutput(back,true)
  monitor.clear()
  monitor.setCursorPos(1,1)
  monitor.print("Current mode:")
  monitor.setCursorPos(1,3)
  monitor.print("Dust gaat naar chest")
end
else
  print("Okeuu dan niet jongee")
end

我知道我已经使用了“end”两次。这是因为当我删除一个时出现错误。

运行程序时出现的错误是:

bios:14: [string ".temp"]:22: '<eof>' expected.

The error I get when I remove the first 'end'.

The error I get when I remove the second 'end'.

编辑 好吧,经过一些建议后,我设法摆脱了错误。 感谢所有回复的人! C: 现在我又遇到了另一个错误,哈哈。 正如建议的那样,我发表了一篇关于它的新帖子:Basic LUA problems

最佳答案

:22: 告诉您错误发生在脚本的第 22 行(即 else)附近。如果您查看 Lua 引用指南,您会发现 else 属于 if 语句,而不是 while 语句。

您的代码可能应该如下所示,因为这里暂时没有意义

if input == ja
then
  ... code ...
else
  ... other code ...
end

关于lua - 如何追踪基本的LUA错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45883407/

相关文章:

c++ - Lua C++ 用户数据矩阵访问元素

lua - 在 Lua 中,是否有一个函数给定一个函数,它将其名称作为字符串返回?

lua - 为什么在 Lua 中使用本地需求?

nginx - 将 LUA 模块添加到 nginx

windows - lua lane 线程间通信

lua - 如何将 ISO 8601 持续时间转换为 Lua 中的格式化字符串?

c++ - 从另一个线程中断 c++ 中的 lua 脚本?

c++ - 与 Lua 链接错误?

c - Lua 加载屏幕 - courotines 与 C 线程

mobile - 将函数作为变量传递并将其分配给仍然能够在 Lua 中引用 "self"的对象