Stormwall

by sh4dow

Build floor tiles that create a force field wall above them when supplied with energy.

Content
5 months ago
1.1
935
Combat

b [fixed] Fix for construction & deconstruction mod errors

6 months ago
(updated 6 months ago)

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!

6 months ago

Update: I've also fixed a minor bug where the first emitter placed doesn't correctly power any plates, regardless of when they're placed. This can be resolved by changing line 401 in tileBuilt from:

      local emitterEntity, emitterIndex = scanForEmitters(surfaceIndex, k.position.x, k.position.y, 0) -- find connectable emitter, if any

to:

      local emitterEntity, emitterIndex = scanForEmitters(surfaceIndex, k.position.x, k.position.y, nil) -- find connectable emitter, if any

The first emitter has emitter index 0, and was thus incorrectly being excluded from the scan.

Thanks!

6 months ago

Thank you for the report/analysis.

The old Stormwalls code was inconsistent about using 0 and nil for "missing" values, and I forgot about 0 being truthy.

The line causing the dying fields error shouldn't even be there anyway - degrading fields are already unlinked from the plate at that point.

The other error shouldn't really matter - the emitterIndex is the entity unit number, which shouldn't be 0 even for the first emitter placed (unless perhaps in a debug world without any entities? But even then you'd usually place something to power the emitter beforehand, so this would be an incredibly fringe edge case). However, since the inconsistent null representation was causing issues (or at least confusion) anyway, I changed the code to generally use nil instead of 0 for "missing"/"disconnected" entries.

New response