Page 1 of 1

Setting color of car-like entities

Posted: Fri Sep 20, 2019 1:53 pm
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.

Re: Setting color of car-like entities

Posted: Fri Sep 20, 2019 5:23 pm
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.)

Re: Setting color of car-like entities

Posted: Sat Sep 21, 2019 11:41 pm
by Pi-C
eradicator wrote:
Fri Sep 20, 2019 5:23 pm
So... make an interface request?
Done! :-)

Re: Setting color of car-like entities

Posted: Thu Sep 26, 2019 4:29 am
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!

Re: Setting color of car-like entities

Posted: Thu Sep 26, 2019 6:54 am
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.

Re: Setting color of car-like entities

Posted: Thu Sep 26, 2019 7:08 am
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.

Re: Setting color of car-like entities

Posted: Thu Sep 26, 2019 7:22 am
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?

Re: Setting color of car-like entities

Posted: Thu Sep 26, 2019 7:30 am
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.

Re: Setting color of car-like entities

Posted: Thu Sep 26, 2019 7:59 am
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!