Transport Belt Direction Indicator


A small script that displays an arrow whenever you're selecting a transport belt entity/ghost, or holding a transport belt item/ghost in your cursor.

Tweaks
2 months ago
2.1
2.35K
Logistics

b [Fixed] Non-recoverable error

2 months ago

The mod Quality Control (2.4.0) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event quality-control::on_configuration_changed
The mod Transport Belt Direction Indicator (1.0.1) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event belt-direction-indicator::on_runtime_mod_setting_changed (ID 71)
belt-direction-indicator/control.lua:25: bad argument #2 of 2 to 'get_player' (string expected, got nil)
stack traceback:
[C]: in function 'get_player'
belt-direction-indicator/control.lua:25: in function <belt-direction-indicator/control.lua:22>
stack traceback:
[C]: in function 'newindex'
__quality-control/control.lua:166: in function 'migrate_upgrade_limits_to_runtime_settings'
quality-control/control.lua:436: in function <quality-control/control.lua:434>

2 months ago

Removing Transport Belt Direction removed the error.

2 months ago
(updated 2 months ago)

Mod author for Quality Control here, I checked into what was happening as I definitely want to support accessibility mods. Any mod that updates runtime settings could trigger this error for Transport Belt Direction Indicator.

Details:
Mod's can raise on_runtime_mod_setting_changed without a player_index. The Transport Belt handler receives this event and calls game.get_player(nil) at line 25, causing the crash. Factorio documents player_index as optional for this event.

Fix:
You could check the player_index property, or could filter the settings handler to "belt-direction-indicator. Or both:

Filter:

 script.on_event(defines.events.on_runtime_mod_setting_changed, function(event)
      if event.setting ~= "belt-direction-indicator" then
          return
      end

      belt_direction_indicator(event)
  end)

Optional guard if you don't want to filter events:

  local player_index = event.player_index
  if not player_index then
      return
  end

  local player = game.get_player(player_index)
  if not player then
      return
  end
2 months ago
(updated 2 months ago)

Edit, fixed the code formatting in the previous post.

2 months ago
(updated 2 months ago)

Thank you a lot for looking into this, the error was probably due to holdover code from when Transport Belt Direction Indicator was still part of Black Rubber Belt Remastered.

Long story short: there was a runtime setting to enable/disable the script mid game, so the direction indicator had to update whenever the player changed the runtime settings. The "enabled/disable belt direction indicator" setting was hidden when TBDI was split, but the check on runtime setting change remained.
I've decided to add back that setting so that in multiplayer games with the mod installed, each player may turn it on/off for themselve.

I've added the snippet of code to check if player_index exists in v1.0.2, hopefully that should prevent this kind of crashes.

2 months ago

When I tried both again, it didn't crash on me, so YAY!

2 months ago

Yay!! Right on! :)

New response