Page 1 of 1

[1.1.91] on_entity_color_changed event is not raised when the new color is nil

Posted: Wed Sep 20, 2023 6:06 am
by asher_sky
It appears the on_entity_color_changed event is not raised when the new color of an entity is nil. It would be nice if it did; a change from something to nothing is still a change.

My use-case for this is: I want to cache the colors of entities so I don't need to access entity.color over and over to get the color, by listening for the event I can just cache the color when it changes and look it up later. But if it changes to nil and the event is not raised then my cache won't be updated and will still think the entity has a color, making the cache inaccurate.

Steps to reproduce:
1. start a new save and spawn in some entities that can be colored, like locomotives.
2. paste the following script into chat to print a message when the event triggers

Code: Select all

/c
script.on_event(defines.events.on_entity_color_changed, function(event)
    game.print({"", event.entity.localised_name, " color changed to: ", serpent.line(event.entity.color)})
end)
3. select one of the entities and paste the following command to change its color to white

Code: Select all

/c game.player.selected.color = {1,1,1}
4. the script from step 2 prints a message to console
5. select the entity again and paste the following command to change its color to nil

Code: Select all

/c game.player.selected.color = nil
6. the script from step 2 does not print a message to console

Re: [1.1.91] on_entity_color_changed event is not raised when the new color is nil

Posted: Sat Oct 07, 2023 4:46 pm
by Rseding91
Thanks for the report. This is now fixed for the next 1.1 release.