Smart Belt Immunity

by tjson

This mod modifies the Belt Immunity Equipment. It turns off the immunity to belts when you're moving in the same direction as the belt is.

Utilities
2 years ago
1.1
2.12K

g Crash in editor mode

2 years ago

Hello,

The mod crash when you use an editor mode (like : https://mods.factorio.com/mod/EditorExtensions where you can enter a character-less god-mode) :

The mod Smart Belt Immunity (0.1.1) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event smart-belt-immunity::on_tick (ID 0)
smart-belt-immunity/control.lua:31: attempt to index field 'character' (a nil value)
stack traceback:
smart-belt-immunity/control.lua:31: in function <smart-belt-immunity/control.lua:11>

Also I see you are running the code in an ontick loop every tick on all players, it might be taking lot of performance for not much action, and may even lag out in a big multiplayer game.

You should use the on_nth_tick function https://lua-api.factorio.com/0.16.43/LuaBootstrap.html#LuaBootstrap.on_nth_tick and tune the time to only run it every 1 or 2 second for exemple (60 or 120 ticks) or even less to massively reduce the mod footprint on runtime.

Also as an optimisation you could fill an array (only on game load and on equiping an armor) of players with immunity equipements when an armor is equiped and contains an armor grid that contains a belt immunity equipements and then check if you actually have an array of players before doing any calculation. This way if no belt immunity is installed on an equiped armor, the mod wouldn't do anything at all and you would only loop once all players in the game to index eligible ones and only loop thoses to check if they are on a belt every nth ticks instead of checking all players every single tick.

Here's an exemple of a mod that checks a bunch of mining drill if any is built and registered in a list to check from every 2 seconds only :
- https://github.com/VortiK/vtk-deep-core-mining/blob/master/control.lua#L126
- https://github.com/VortiK/vtk-deep-core-mining/blob/master/lib/feature.lua#L66

2 years ago

Hi @VortiK! I'll work on this soon! Just been a bit busy the past couple of days and will still be busy. Sorry for the inconvenience this has had but I assure you that your report has been seen and noted. Thank you for the suggestions and have a nice day/night!

2 years ago

Just encountered this issue too.

2 years ago

The new update should have fixed this! Thank you for being so patient.

2 years ago

I'm still getting this error in editor-

The mod Smart Belt Immunity (0.2.0) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event smart-belt-immunity::on_player_changed_position (ID 85)
smart-belt-immunity/control.lua:44: attempt to index field 'character' (a nil value)
stack traceback:
smart-belt-immunity/control.lua:44: in function <smart-belt-immunity/control.lua:28>

2 years ago

I'm using Editor Extensions which syncs armor between the player and editor if that helps

2 years ago

Hi sorry! I am unable to reproduce this issue on my own client. I got into a game, and in the console, I input "/editor, " which seems to work okay. I also tried going onto the map editor option on the main menu and making a new scenario with all the stuff, but the issue didn't pop up. I even installed Editor Extensions, and I can't seem to reproduce this issue. Here's a gist link to a modified version of the control.lua, replace it in hopes of it working?

https://gist.github.com/json-commits/6ec1adcf29b370d9683890e2af90de3d

2 years ago

That seems to solve it! Maybe Krastorio was involved? It changes the belt immunity prototype somehow.

1 year, 8 months ago

First time using editor extensions, same crash as Iron was getting, whether I use /editor or open the editor extensions scenario. I don't get this error when going into creative mod's god mode, and have never installed Krastorio, if that helps at all.

New response