Custom Color

by DiRten

More Colors for Vehicles, Players, Trains, Train Stops, Tanks, Cargo-wagons, Fluid-Wagons, Spidertrons -RGB value (Including color saturation) -Copy/Paste color (Shift-RMB -> Shift-LMB) *Vehicle don't change color with player*

Utilities
1 year, 5 months ago
1.1
4.08K
Transportation Trains

g Vehicles cause game to crash

1 year, 8 months ago

As soon as I get out of a tank or car, the game crashes with the following:

The mod Custom Color (3.1.1) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event CustomColor::on_player_driving_changed_state (ID 28)
CustomColor/libraries/functions/cars.lua:46: attempt to index field '?' (a nil value)
stack traceback:
CustomColor/libraries/functions/cars.lua:46: in function <CustomColor/libraries/functions/cars.lua:38>

This does not happen if I ride in a train, I haven't tested this with the spidertron yet.

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

I experienced the same crash after adding the mod to an existing single-player game. The problem is that in single player mode, on_player_joined_game will be raised only once (directly after on_player_created), not when loading a saved game. The only place where player data could be initialized in this case would be in on_configuration_changed, but the mod only migrates tables there and doesn't create new ones. (@DiRten: By the way, why didn't you use migration files? Each migration file will be run only once, not each time a mod has been changed.)

I've fixed the crash by replacing lines 26 and 27 of libraries/update.lua with this:

for _, v in pairs(game.players) do
    global.player_info[v.index] = global.player_info[v.index] or {color = v.color}
    if v.gui.relative.player_color_sprite_button_open ~= nil then
1 year, 7 months ago

I apologize, I am rather new to modding with Factorio and wasn't fully aware of using migration files.

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

I apologize, I am rather new to modding with Factorio and wasn't fully aware of using migration files.

Sorry, my bad: That was meant for @DiRten! Migration files are part of the mod. I've edited my first post to make this more obvious. :-)

1 year, 7 months ago

Ha! No worries. Had me going for about 10 minutes scratching my head wondering why I didn't use migration files and spent another 10 minutes researching the topic....

1 year, 5 months ago

I experienced the same crash after adding the mod to an existing single-player game. The problem is that in single player mode, on_player_joined_game will be raised only once (directly after on_player_created), not when loading a saved game. The only place where player data could be initialized in this case would be in on_configuration_changed, but the mod only migrates tables there and doesn't create new ones. (@DiRten: By the way, why didn't you use migration files? Each migration file will be run only once, not each time a mod has been changed.)

I've fixed the crash by replacing lines 26 and 27 of libraries/update.lua with this:

for _, v in pairs(game.players) do
global.player_info[v.index] = global.player_info[v.index] or {color = v.color}
if v.gui.relative.player_color_sprite_button_open ~= nil then

Thanks for the help! I'll be doing this in the near future.

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

I did exactly what you said for the fix, now I'm getting this:

CustomColor/control.lua:19: CustomColor/libraries/update.lua:42: ')' expected (to close '(' at line 1) near 'for'
stack traceback:
[C]: in function 'require'
CustomColor/control.lua:19: in main chunk

What am i dong wrong?

1 year, 2 months ago

you can disregard, got it working

5 months ago

I experienced the same crash after adding the mod to an existing single-player game. The problem is that in single player mode, on_player_joined_game will be raised only once (directly after on_player_created), not when loading a saved game. The only place where player data could be initialized in this case would be in on_configuration_changed, but the mod only migrates tables there and doesn't create new ones. (@DiRten: By the way, why didn't you use migration files? Each migration file will be run only once, not each time a mod has been changed.)

I've fixed the crash by replacing lines 26 and 27 of libraries/update.lua with this:

for _, v in pairs(game.players) do
global.player_info[v.index] = global.player_info[v.index] or {color = v.color}
if v.gui.relative.player_color_sprite_button_open ~= nil then

I can't get this to work, I still get the same error.

When you say 'replace lines 26 and 27' do you mean put these three lines instead? It's kinda confusing because you put 3 lines of code that are supposed to replace 2 lines of code, maybe I got something mixed up?

5 months ago
(updated 5 months ago)

@Bosdragon : Sorry it took me so long to reply!

I experienced the same crash after adding the mod to an existing single-player game. The problem is that in single player mode, on_player_joined_game will be raised only once (directly after on_player_created), not when loading a saved game. The only place where player data could be initialized in this case would be in on_configuration_changed, but the mod only migrates tables there and doesn't create new ones. […]

I've fixed the crash by replacing lines 26 and 27 of libraries/update.lua with this:

for _, v in pairs(game.players) do
    global.player_info[v.index] = global.player_info[v.index] or {color = v.color}
    if v.gui.relative.player_color_sprite_button_open ~= nil then

I can't get this to work, I still get the same error.

Strange …

When you say 'replace lines 26 and 27' do you mean put these three lines instead? It's kinda confusing because you put 3 lines of code that are supposed to replace 2 lines of code, maybe I got something mixed up?

Yes, the 3 lines are meant to replace 2 lines in the original file. Actually, I've only added the second line, the others haven't changed. My idea was that this directive would make it easier to get the new line at the correct position. I'm sorry that confused you!

Basically, I want to check for each player in the game whether global.player_info already exists for that player, and initialize the table if it doesn't exist. Therefore, this line must be after for _, v in pairs(game.players). But I must always check this -- whether v.gui.relative.player_color_sprite_button_open exists or not. That's why the new line must be placed before the line starting with ìf`. Hope that helps. :-)

New response