Quick Ride


Quickly deploy and enter vehicules from your inventory with a simple keyboard shortcut.

Tweaks
2 months ago
2.0
461
Transportation

b Incorrect handling of `on_runtime_mod_setting_changed` event

2 months ago

Your event handler for the on_runtime_mod_setting_changed event does not correctly check if the event came from your setting being changed.
First, there are actually two handlers for the event, which is invalid and the second one overrides the first one. The first handler occurs in control.lua, line 439, and the second occurs in control.lua, line 535.

In the second handler (which does run), you do not check if the setting that changed is your mod's setting, so this code always runs, which normally is not an issue (just inefficient). However if a mod changes it's own setting before your mod initializes (which is likely because your mod id starts with "q"), your player_storage data is not yet set up and causes an error. See this GitHub issue. Note that the error originates from your mod causing a nil index error on control.lua, line 539.
The first handler (which never runs) does attempt to validate the setting, but it checks for the "mod_name" field of the event, which is not a real field on any event and as such this event handler would actually never run.

To fix this, remove the second event handler completely, and edit the first event handler so that it checks for the event.setting field first (before attempting to get your player data) and returns early if it doesn't match:

script.on_event(defines.events.on_runtime_mod_setting_changed, function(event)
if event.setting ~= "qr-double-tap-delay" then return end

local player_storage = storage.players[event.player_index]
local player = game.get_player(event.player_index)
if not player then return end

player_storage.double_tap_delay = player.mod_settings["qr-double-tap-delay"].value * 60
end)

2 months ago

Looks like an oversight. I should have the time to fix that tonight.

Thanks for the heads up

2 months ago

I just released 1.2.3. I tested with the mod specified in the issues and the problem seems to be fixed.

2 months ago

Cool, just tested and it works for me too, thanks!

New response