Vehicle Cruise Control deprecated

by mk-fg

Adds GUI panel with buttons to toggle acceleration and brakes, so that you don't have to hold W or S.

Utilities
1 year, 10 months ago
0.16 - 1.1
937

b Crash on starting a new game

1 year, 10 months ago
(updated 1 year, 10 months ago)

Hi! I get the following error on starting a new game with this mod enabled:

4632.244 Error MainLoop.cpp:1288: Exception at tick 1: The mod Vehicle Cruise Control (0.0.8) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event Vehicle_Cruise_Control::on_tick (ID 0)
__Vehicle_Cruise_Control__/control.lua:83: attempt to index field 'cc_state' (a nil value)

The problem is here:

script.on_configuration_changed(function(data)
        if (global.init or 0) < 1
                then global.init, global.guis, global.cc_state = 1, {}, {} end
end)

script.on_init(function() strict_mode_enable() end)
script.on_load(function() strict_mode_enable() end)

You don't initialize the global tables in on_init, just in on_configuration_changed -- which will only run if the mod has been added to a running game or if mods/modsettings have been changed, but not if a new game is started.

EDIT: If on_configuration_changed is run because some other mod has changed, global.guis and global.cc_state will always be reset to {}. Is that intentional, or shouldn't you preserve existing tables?

1 year, 10 months ago

Ah yes, sorry, I seem to have forgotten that on_configuration_changed shouldn't run for new games when updating that and didn't test with one, my bad.
It was reported on github that there was a desync issue due to the usual "local GUIs" and such, was fixing those, will update.

If on_configuration_changed is run because some other mod has changed, global.guis and global.cc_state will always be reset to {}.

Only if global.init is unset, otherwise nothing will change, so should be fine, I think.

1 year, 10 months ago

Should be fixed in 0.0.9. Thanks for reporting!

1 year, 10 months ago

If on_configuration_changed is run because some other mod has changed, global.guis and global.cc_state will always be reset to {}.

Only if global.init is unset, otherwise nothing will change, so should be fine, I think.

Sorry, of course you're right! Seems I was so confused by not seeing the common global.guis = global.guis or {} that I didn't notice the if-then wrapper. :-)

1 year, 10 months ago

Should be fixed in 0.0.9. Thanks for reporting!

THanks for fixing the bug! I'll report back later whether it really worked …

1 year, 10 months ago

not seeing the common global.guis = global.guis or {}

Idea there is to use a data migration number, i.e. init=0 -> set globals, init=1 -> migrate to 2, init=2 -> migrate to 3, ...
But doubt it's actually necessary in this trivial mod, so could've easily been global.guis or {} :)

1 year, 10 months ago

I'll report back later whether it really worked …

I did test it with new game a couple times this time, so totally should.

1 year, 10 months ago

Yes, seems to work now. :-)

not seeing the common global.guis = global.guis or {}

Idea there is to use a data migration number, i.e. init=0 -> set globals, init=1 -> migrate to 2, init=2 -> migrate to 3, ...

So this is a replacement for the regular migration scripts? Interesting, I've always wondered if it wouldn't break things if a mod with a heap of migration scripts would be added to an existing game -- seems a bit iffy whether the migration scripts would really be run in the intended order.

1 year, 10 months ago

They probably should run in strict documented order.
I've only used migrations for entities, and forgot that .lua ones exist too, which are likely a better way to do same thing.

1 year, 10 months ago

I see! I've repeatedly made changes to the data structure of some mods, so Î've used the Lua migration scripts quite a lot. It's a bit cleaner than having the migration code mixed with the regular code, but that may be just a matter of taste …

New response