Water As A Resource Extended deprecated


Turns Water into a non infinite resource. Water bodies get removed and replaced by solid ground. Offshore Drains allow water & oil to be put back into these depleted areas.

Content
1 year, 9 months ago
1.1
335
Environment

b Crash when placing offshore drain

1 year, 9 months ago
(updated 1 year, 9 months ago)

Hellos,

When attemping to place an offshore drain, I get the following error:

Error while running event WaterAsAResourceExtended::on_built_entity (ID 6)
__WaterAsAResourceExtended__/control.lua:2027: attempt to index global 'OPentity' (a nil value)
stack traceback:
    __WaterAsAResourceExtended__/control.lua:2027: in function <__WaterAsAResourceExtended__/control.lua:2005>

I did some debugging of the BuiltOffShore function. Game makes it through the large if statement event.created_entity.name == "offshore-drain" and also through the if-Krastorio2 if game.active_mods["Krastorio2"] then. event.created_entity.name == "offshore-pump" is false because this is an offshore drain and not a pump, and event.created_entity.name == "kr-electric-offshore-pump" is also false, so then it doesn't execute any code but the variable OPentity still isn't set.

Then when the code reaches the next line, if OPentity.name == "offshore-pump", OPentity is nil, thus causing the error. Since the large if statement seems to be set up to run when a drain is being placed, it seems like you're missing code to set OPentity.

Since the rest of the function uses OPentity extensively, I feel like every branch of the big if tree must either OPentity = event.created_entity; global.Player = OPentity.last_user or goto NOTVALID, otherwise it'll cause an error.

1 year, 9 months ago

Thank you for this report and trying out the mod. I'm not really familiar with all of the details in the control script as this is just extension to existing project. However, I've made potential changes (untested yet as I don't have time for that, sorry for that) and uploaded new version. You can check whether this works for your problem or suggest some other improvement.

BTW. Im not familiar with how offshore-drains really work - Im not using them in my factory. The challenge I've taken is to sustain the water areas with their natural regeneration rate, increasing the regeneration by producing Waterfill (another mod) which takes up space as a cost.

I've moved the calls you mention to be always executed after first condition:

if event.created_entity.name == "offshore-pump" and event.created_entity.force.name ~= "neutral" or event.created_entity.name == "offshore-drain" or event.created_entity.name =="pumpjack" or event.created_entity.name == "kr-electric-offshore-pump" or event.created_entity.name == "copper-pump"then
OPentity = event.created_entity
global.Player = OPentity.last_user
if game.active_mods["Krastorio2"] then
if event.created_entity.name == "offshore-pump" then
-- IGNORE FIRST OFFSHORE TRIGGER UNLESS AAI IS ACTIVE
if game.active_mods["aai-industry"] then

            else
                goto NOTVALID
            end
        elseif event.created_entity.name == "kr-electric-offshore-pump" then

        end
    else

    end
else
    goto NOTVALID
end

New response