Setting color of car-like entities

Place to get help with not working mods / modding interface.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Setting color of car-like entities

Post by Pi-C »

According to the release notes of 0.17.43,
Car/tank color keeps the color of the last user.
I want to set the color of cars (rather, entities where type == "car") to the color of a certain user -- whether another user is inside that car or not. Is that impossible now? I've tried both

Code: Select all

entity.color = game.players[index].color
and

Code: Select all

entity.last_user = game.players[index]
Here is some logging output that shows the values before/after color and last_user have been set.

Color:

Code: Select all

Try to recolor the crawler with color of test
Show car.color: |nil| (nil)
Show game.players[index].name: |test| (string)
Show game.players[index].color: 
Printing keys/values for table with length 0
k: r	v: 0.81499999761581
k: g	v: 0.024000000208616
k: b	v: 0
k: a	v: 0.5
Executed: car.color = game.players[index].color
Show new car.color: |nil| (nil)
Show car.name: |crawler| (string)

Trying to set last_user
Show car.last_user.name: |Pi-C| (string)
Executed: car.last_user=game.players[index]
Show car.last_user.name: |test| (string)
 
I already expected that setting the color attribute would fail, given this caveat: "Returns nil if this entity doesn't use custom colors"[*], but setting last_user works -- and does not change the color of the vehicle. Can it still be done, somehow?


[*] Guess I misinterpreted that: I thought it would return nil if one used default (i.e. the player colors used by vanilla) instead of custom colors -- now I suppose it's rather that the entity must support the color attribute.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Setting color of car-like entities

Post by eradicator »

color :: Color [Read-Write]
The character, rolling stock, train stop, flying text, corpse or simple-entity-with-owner color. Returns nil if this entity doesn't use custom colors.
Car isn't in the list, and trying in-game that does seem to be correct. The car seems to just store *a* color. The "of the last_user" bit is just context explanation of where it gets the color from. If you change user color after riding a car the car keeps your old color.

So... make an interface request? (Alternatively a moderator could move this.)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Setting color of car-like entities

Post by Pi-C »

eradicator wrote:
Fri Sep 20, 2019 5:23 pm
So... make an interface request?
Done! :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

swni
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Sat Mar 05, 2016 1:54 am
Contact:

Re: Setting color of car-like entities

Post by swni »

This is surprising to me since turrets do change color when the player changes color. But I just tested and cars only change color if the player is currently inside. (And thus I've found for the first time an actual use for my Rainbow Player Color mod.)

By the way - thanks for your changelog tutorial!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Setting color of car-like entities

Post by eradicator »

swni wrote:
Thu Sep 26, 2019 4:29 am
This is surprising to me since turrets do change color when the player changes color.
Turrents (and some others) color is bound to the force, not the player. In singleplayer you just can't observe the difference.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Setting color of car-like entities

Post by darkfrei »

Yeah, the turret color is always synced to the force color and force color is always synced to the first player in this force.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Setting color of car-like entities

Post by Pi-C »

darkfrei wrote:
Thu Sep 26, 2019 7:08 am
Yeah, the turret color is always synced to the force color and force color is always synced to the first player in this force.
Honest question: What if the first player dies or disconnects? Will the force/turret color change automatically to that of the second player?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Setting color of car-like entities

Post by eradicator »

Pi-C wrote:
Thu Sep 26, 2019 7:22 am
darkfrei wrote:
Thu Sep 26, 2019 7:08 am
Yeah, the turret color is always synced to the force color and force color is always synced to the first player in this force.
Honest question: What if the first player dies or disconnects? Will the force/turret color change automatically to that of the second player?
No. The LuaPlayer is not the character LuaEntity, it is always present unless a script deletes it (on_player_removed). Force color will only take the color of another player if the first player in a force leaves the force. Forces without players are black in color btw.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Setting color of car-like entities

Post by Pi-C »

Right, the player/character division … While debugging my mod, I saw that the init-function was called for both of my two players although I hadn't even started the second Factorio instance. Thanks for pointing this out again!
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding help”