Player Trails


Draws colorful glowing trails wherever you go

Tweaks
4 months ago
1.1
1.01K

b Crash on starting new game with "Project Cybersyn"

1 year, 2 months ago

I've got a save file with a ton of mods for debugging one of my mods, including yours and Project Cybersyn - Logistics Train Dispatcher. On starting a new game, I get this crash:

 224.514 Error AppManagerStates.cpp:2520: The mod Project Cybersyn (1.2.13) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event cybersyn::on_init()
The mod Player Trails (0.0.1) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event player-trails::on_runtime_mod_setting_changed (ID 61)
Expected LuaPlayer, index, or name.
stack traceback:
  [C]: in function 'get_player_settings'
  __player-trails__/control.lua:49: in function 'initialize_settings'
  __player-trails__/control.lua:64: in function <__player-trails__/control.lua:63>
stack traceback:
  [C]: in function '__newindex'
  __cybersyn__/scripts/main.lua:904: in function <__cybersyn__/scripts/main.lua:901>

Cybersyn will change a global setting in on_init:

    script.on_init(function()
            local setting = settings.global["cybersyn-invert-sign"]
            setting.value = false
            settings.global["cybersyn-invert-sign"] = setting
            mod_settings.invert_sign = false
            init_global()
            setup_se_compat()
    end)

Your mod expects that on_runtime_mod_setting_changed will have event.player_index:

local function initialize_settings(index)
  if not global.settings then
    global.settings = {}
  end
  local player_settings = settings.get_player_settings(index)

  …

end

script.on_event(defines.events.on_runtime_mod_setting_changed, function(event)
  initialize_settings(event.player_index)
end)

However, according to the description player_index is an optional value:

If the setting_type is "global" and it was changed through the mod settings GUI, this is the index of the player that changed the global setting. If the setting_type is "runtime-per-user" and it changed a current setting of the player, this is the index of the player whose setting was changed. In all other cases, this is nil.

1 year, 1 month ago

Thank you for the report, I appreciate the explanation of what’s going on, it looks like I forgot to add a nil check! I will work on getting a fix published soon.

1 year, 1 month ago

Adding a nil check will prevent a crash, but you'd still read the settings each time a player changes ANY map or user setting. It would be better If you'd react just to the settings you really care about:

script.on_event(defines.events.on_runtime_mod_setting_changed, function(event)
  -- Filter out settings of your own mod
  if event.setting:match("^player%-trail%-") then

    -- Read user settings
    if event.setting_type == "runtime-per-user" then
      initialize_settings(event.player_index)

    -- -- Read global/map settings (could become necessary if you add new settings)
    -- else
      -- initialize_global_settings()
    end
  end
end)

New response