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.