Hi, I played around with the code to see if I could solve two errors I encountered, related to building plates outside the range of any emitters, and fields dying while not over any plate.
The building plates error can be resolved by changing line 761 in scanForEmitters
from return 0, 0
to return nil, 0
. This allows line 405 in tileBuilt
to correctly detect when there is no emitter, since 0 is truthy in Lua.
The fields dying error can be resolved by changing line 984 in tick
from:
global.plates[j[3]][j[4]][j[5]][3] = 0 -- plate no longer has a linked field
to:
local plate_surface = global.plates[j[3]] -- get the correct surface
if plate_surface then
local plate_x = plate_surface[j[4]] -- get the correct x-coordinate
if plate_x then
local plate = plate_x[j[5]] -- get the correct plate
if plate then
plate[3] = nil -- plate no longer has a linked field
end
end
end
I wasn't sure if any of these fields are guaranteed to be populated, so I checked all of them just to be on the safe side.
Thank you!