How can I fix this lua runtime error in pico-8? - lua

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.
Error in PICO-8
Discord Comment
Github Code

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.
function getrnd(arr)
return arr[1+flr(rnd(#arr))]
end
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:
repeat
local r=getrnd(rpot)
if r
placed+=infestroom(r)
del(rpot,r)
end
until #rpot==0 or placed>maxmons[floor]

Related

How to add a page break before header automatically in pandoc

I need to convert a markdown document into a Word document.
I need it so that before each header there is a page break.
For example, here, a page break would be inserted before # Heading 1 and before # Heading 2. I wouldn't mind if it skipped the very first one if there is no content before it in the document.
# Heading 1
Hello
# Heading 2
World
I have found this Lua filter, but, as far as I understand, it's just for Latex and it's not automatic.
I have tried to write a Lua script myself, but failed, because I do not understand well how pandoc works.
For example, I have tried returning a Para with the contents of the previous one + a page break from the Header function like this:
function Header(el)
if el.level == 1 then
local t = { pandoc.RawBlock('openxml', '<w:p><w:r><w:br w:type="page"/></w:r></w:p>'), el }
return pandoc.Para(t)
end
return el
end
However, it just ends up wiping all of the headers.
I have tried a few other alterations of the same idea, neither of which worked.
The trouble in Lua is mainly the fact that there is no static analysis and no Intellisense. I may be doing something completely inadequate in this code without any compiler errors and without even realising it.
I believe the following should fix that:
local pagebreak = '<w:p><w:r><w:br w:type="page"/></w:r></w:p>'
function Header(el)
if el.level == 1 then
-- return both the page break and the header as a list
return { pandoc.RawBlock('openxml', pagebreak), el }
end
-- No `return el` needed, as not returning any value is the same as
-- returning the original value.
end
The error reporting of pandoc during unmarshalling, i.e., while retrieving objects from Lua, is not great, to say the least. Ideally, pandoc should report the type error that comes from wrapping a list of "blocks" in a Para, as that constructor should only accept "inlines".
In case you are curious: I'm working on fixing this by switching to a different marshalling strategy, see this PR. It's taking a while, but we'll get there.

PowerDNS - DNSQuestion is always nil

I have setup a PowerDNS (4.0.4-1+deb9u4) upon Debian 9 with a MySQL backend successfully and the system was resolving hosts correctly. I am attempting to add scripting to the recursor and have used the examples, Lua script examples. I have pointed the pdns-resolver's conf correctly at my lua script, and I see my log statements print correctly, but I am consistently receiving an error regarding the DNSQuestion instance being empty for all of the example lua functions.
For example:
function preresolve(dq)
pdnslog("Got question for "..dq.qname:toString().." from "..dq.remoteaddr:toString().." to "..dq.localaddr:toString())
return true;
end
Results in :
STL error (a.root-servers.net/A from 127.0.0.1): Trying to cast a lua variable from "nil" to "b" (meaning the DNSQuestion instance is null).
Clearly the lua script is running, but for some reason, all the dq instances are empty.
Is there anything that I may have misunderstood or am missing that would cause the parameter to be nil?
Have your function return true or false so it will not return nil by default.

Error attempt to index a nil value (upvalue "cfg)

I was moving some map files, and I rebooted my server (FiveM) and when I called it again it started to give this problem, I undo everything I did, I put the old files again, but the error kept happening. And I do not know what to do to solve it.
I threw all the changed files back to normal, but it did not solve anything.
local cfg = module("cfg/blips_markers")
-- add additional static blips/markers
AddEventHandler("vRP:playerSpawn",function(user_id, source, first_spawn)
if first_spawn then
for k,v in pairs(cfg.blips) do
vRPclient.addBlip(source,{v[1],v[2],v[3],v[4],v[5],v[6]})
end
for k,v in pairs(cfg.markers) do
vRPclient.addMarker(source,{v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11]})
end
end
end)
Inside the server the blip_markes are gone and some player data too, because of that.
A quick debug would be to assign cfg the value of an integer, if your problem solves, you know that something is wrong with module("cfg/blips_markers"). However, please provide the code associated with module("cfg/blips_markers").

I am getting the following errors with my Garry's Mod server

I've got an addon on my server that basically allows you to create territories. On top of that, I have one which allows you to make permanent properties, which players own even when they aren't online. Additionally, you are able to save the props inside these permanent buildings so that when you next get on, the props are all still there.
It was working fine, but I now seem to be encountering the following error whenever I save the props inside my house and restart the server. Also, a lot of the houses don't seem to work. But, when I unsave the props inside a house and restart, everything is back to normal.
The error
[ERROR] addons/darkrpmodification-master/lua/darkrp_modules/territory/sh_init.lua:514: bad argument #1 to 'pairs' (table expected, got nil)
1. pairs - [C]:-1
2. LoadProps - addons/darkrpmodification-master/lua/darkrp_modules/territory/sh_init.lua:514
3. tsetUpDoors - addons/darkrpmodification-master/lua/darkrp_modules/territory/sv_init.lua:273
4. unknown - addons/darkrpmodification-master/lua/darkrp_modules/territory/sv_init.lua:290
Code
function BuyableTerritory:LoadProps(steamid, t)
for k, v in pairs(t) do
local e = ents.Create("prop_physics")
e:SetPos(v.pos)
e:SetAngles(v.ang)
e:SetModel(v.model)
if v.color then
e:SetColor(v.color)
end
if v.material then
e:SetMaterial(v.material)
end
e:Spawn()
e.permaOwner = steamid
e:GetPhysicsObject():EnableMotion(false)
end
local ply = DarkRP.findPlayer(steamid)
if IsValid(ply) then
self:SetPropsOwner(ply, ply:SteamID())
end
The code starts at line 513, so the second line in is the one having problems. Thank you.
Just read the error message. It tells you that the input to pairs() is nil instead of the expected table. pairs is a so called iterator. It only works with a Lua table as input.
Your input t to BuyableTerritory:LoadProps(steamid, t) is not valid.
You either have to change that or check if t is a table befor you call pairs(t) to prevent the error from happening.
Go to line 273 of sv_init.lua to find out whats going on.

Lua error for WoW addon (Tukui)

I don't have a lot of coding experience, did some C a few years ago, so that helps, but Lua handles things a bit differently, so I can't keep track.
I sometimes (not always) get this error when a friend or guildy logs into the game:
Date: 2013-06-14 16:57:57
ID: -1
Error occured in: Global
Count: 4
Message: ..\AddOns\Tukui\scripts\chat.lua line 335:
attempt to concatenate upvalue 'classColor' (a nil value)
Debug:
[C]: ?
Tukui\scripts\chat.lua:335: AddMessage()
..\FrameXML\ChatFrame.lua:2755: ChatFrame_MessageEventHandler()
..\FrameXML\ChatFrame.lua:2491: ChatFrame_OnEvent()
...s\WIM\Libs\LibChatHandler-1.0\LibChatHandler-1.0.lua:281:
...s\WIM\Libs\LibChatHandler-1.0\LibChatHandler-1.0.lua:252
...s\WIM\Libs\LibChatHandler-1.0\LibChatHandler-1.0.lua:308:
...s\WIM\Libs\LibChatHandler-1.0\LibChatHandler-1.0.lua:296
I have to do a reload of the ui after this happens to be able to see chat text again for that person.
Line 335 in that .lua file is this:
text = replace(text, "^|Hplayer:(.+)|h%[(.+)%]|h", "|Hplayer:%1|h|cff"..classColor.."%2|r|h")
Now I've learned that the .. indicates the concatenate function, but that isn't really helping me.
I don't know if this is enough information, but if you need it I can post the whole local function or whatever else is required.
If it makes any difference, I'm running the 3.3.5a WoW client.
You are probably using a global that gets defined from some other addon in a now deterministic way
While the (classColor or "") will get you rid of the error, you should try and find why that variable (classColor) is sometimes defined and sometimes not. Maybe it happens only for certain classes?
A simple hack would be to just replace
..classColor..
with
..(classColor or "")..
where it will select a blank string when classColor has no value assigned to it.

Resources