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

This subforum contains all the issues which we already resolved.
Post Reply
asher_sky
Inserter
Inserter
Posts: 44
Joined: Sun Oct 18, 2020 7:13 pm
Contact:

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

Post 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

Rseding91
Factorio Staff
Factorio Staff
Posts: 13220
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post by Rseding91 »

Thanks for the report. This is now fixed for the next 1.1 release.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Resolved Problems and Bugs”