如何修复 pico-8 中的 lua 运行时错误?
我正在按照您的 roguelike 教程进行操作,但遇到了一个我不知道如何解决的问题。这是我第一次用 Lua 编码
If r.nospawn then return 0
--Attempt to index local "R" (a nil value)
,我询问了 PICO-8 Discord 服务器,他们试图帮助我,但我仍然不完全理解,我不想再用这个问题纠缠他们。我在 PICO-8 上的文件名称称为 Rogue - 如果这与该问题有关。
这是错误的图片、我收到的不和谐评论以及 GitHub 上完整代码列表的链接。
I'm following your roguelike tutorial and have encountered a problem I do not know how to solve. This is my first-time coding with Lua
If r.nospawn then return 0
--Attempt to index local "R" (a nil value)
I asked the PICO-8 discord server, they tried to help me, but I still don't fully understand, and I did not want to pester them further with the issue. The name of my file on PICO-8 is called Rogue - if that has anything to do with the issue.
Here's a picture of the error, the discord comment I received, and a link to the full list of code on GitHub.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您缺少一个简单的失败情况。即当删除RPOT中的所有条目时会发生什么。然后
local r = getrnd(rpot)
应返回null。这本身就是一个错误,即总会从那里分配一些东西。但是,Getrnd将失败。
在ARR为空的情况下,您将尝试返回元素1,这将超出界限。我不知道lua,但它可能会为您返回NULL,这导致下一个问题。但这有一个简单的修复:
I think you are missing a simple failure case. i.e. what happens when all the entries in rpot have been removed. Then
local r=getrnd(rpot)
should return null. That might be an error in it's own right i.e. there should always be something to allocate from there.However getrnd will fail.
In the case when arr is empty you will try and return element 1, which will be out of bounds. I don't know lua but it might return null for you which leads to the next problem. But that has a simple fix: