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.
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: