Diggs

by Jardee

This mod adds text on top of mining entity and shows how much time left to mine everything underneath.

Utilities
2 years ago
0.18 - 1.1
7.06K

b Realistic Fusion 1Mt Shell Crash

2 years ago
(updated 2 years ago)

When attempting to blow up my base with a 1Mt artillery shell with the mods Diggs, True Nukes, and Realistic Fusion Weaponry, I get the following error:

The mod RFP Addon: Weaponry (1.5.8) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event
RealisticFusionWeaponry::on_script_trigger_effect (ID 152)
Error when running interface function True-Nukes
Scripts.atomicWeaponHit: The mod Diggs (1.0.5) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event Diggs::on_entity_died (ID 4)
LuaEntityAPI call when LuaEntity was invalid.
stack traceback:
[C]: in function 'index'
__Digs
/control.lua:132 in function <Digs/control.lua:128>
stack traceback:
[C]: in function 'die'
True-Nukes/control.lua:1497: in function
'optimisedChunkLoadHandler'
True-Nukes/control.lua:1876: in function
<True-Nukes/control.lua:1842>
stack traceback
[C]: in function 'call'
_RealisticFusionWeaponly__control.lua:19: in function
<RealisticFusionWeaponry__/control.lua:2>

Edit: After testing without diggs, it does not show up in the error (different mod objects on die instead). My apologies.

2 years ago

I've found the problem:
You iterate your main table without checking the entities in it are valid when you are checking for destroyed entities. My mod shouldn't be destroying any of them without warning, but maybe when so many entities are killed at once, it gets confused.

Specifically:

function miningDrillDestroyEventHandler(event)
if global.Drills ~= nil then
if #global.Drills > 0 then
for k, entity in pairs(global.Drills) do
if (entity.entity.position.x == event.entity.position.x) and (entity.entity.position.y == event.entity.position.y) then
rendering.destroy(entity.text)
table.remove(global.Drills, k)
break
end
end
end
end
end

To fix this, try:

function miningDrillDestroyEventHandler(event)
if global.Drills ~= nil then
if #global.Drills > 0 then
for k, entity in pairs(global.Drills) do
if (entity.entity.valid) then
if (entity.entity.position.x == event.entity.position.x) and (entity.entity.position.y == event.entity.position.y) then
rendering.destroy(entity.text)
table.remove(global.Drills, k)
break
end
else
rendering.destroy(entity.text)
table.remove(global.Drills, k)
break
end
end
end
end
end

2 years ago

oh, also, if you want a performance improvement for destroying drills, try making the drills table indexed by x, then by y, then have the drill as the value. You never have to search for a drill by entity, but often do by location.

2 years ago

Replaced the code block you mentioned with the suggested code. Can confirm with Diggs enabled, the 1Mt explosion does not throw any errors.

For improving the performance of destroying drills, they're roughly 1/6th of the total entities in my case, so trying to code what you suggested with my limited experience would not be worth it. Thanks though.

New response