Better Ecology

by Byzzee

Adds in some stuff such as wind turbines, tree planters and air filters to make your factory a bit more eco-friendly ^_^

Content
14 days ago
1.1 - 2.0
2.89K
Environment Manufacturing Power

b Crash on mass-deconstruct [Fixed]

6 months ago
(updated 6 months ago)

Hi, just wanted to let you know that an on_tick control script crashes to the menu whenever I mass-deconstruct two or more entities from your mod! Example:


The mod Better Ecology (0.1.1) caused a non-recoverable error.
Please report this error to the mod author.
Error while running event better-ecology::on_tick (ID 0)
LuaEntity API call when LuaEntity was invalid.
stack traceback:
[C]: in function '__newindex'
__better-ecology__/control.lua:47: in function
<__better-ecology__/control.lua:21>

I think you need to add in some checks for entity validity (link), like this:


for _, turbine in ipairs(global.wind_turbines) do
    if turbine.valid then
        turbine.power_production = global.wind_speed
    end
end

This should be done for the tree planter and air purifier as well. Hope this helps!

6 months ago
(updated 6 months ago)

Update: It seems to not be an issue if they are marked for deconstruction and then collected with drones normally, but immediate deconstruction enabled by a mod such as Creative Mod will cause the crash. (There could be other instances as well. Validity check generally seems like a good idea, at least to safeguard against unexpected actions by other mods.)

6 months ago
(updated 6 months ago)

Adding a script with script_raised_destroy also solves the issue:

script.on_event(defines.events.script_raised_destroy, function(event)
    unregisterModEntity(event.entity) end, {
        {filter = "name", name = "tree-planter"},
        {filter = "name", name = "air-purifier", mode = "or"},
        {filter = "name", name = "wind-turbine", mode = "or"}
    }
)

It registers the event of an entity being destroyed through a script (for example by another mod), so said entity can be removed from the global table like it should. It is always a good idea to include this event when checking for removed entities.

6 months ago

Yeah, I've already had this event implemented for "script raised" construction, but I simply forgot to add the same for destroy, I guess.
Update to 0.1.2. Should work just fine now. Thank you for your report.

6 months ago

That's great and you're welcome!

You may also want to add a script with script_raised_revive together with RegisterModEntity(event.entity).

New response