Page 1 of 1

LuaPlayer.entity_copy_source is actually associated to the character, not the player

Posted: Sat Jul 23, 2022 7:16 pm
by Wiwiweb
Problem reproduction
I have this setup with 2 characters and a machine (save file is attached to this post):
Screenshot 2022-07-23 121100.png
Screenshot 2022-07-23 121100.png (74.82 KiB) Viewed 821 times
1) I am currently controlling the top character. I shift-right click the assembling machine.
2)

Code: Select all

/c game.print(game.player.entity_copy_source.name)
gives me "assembling-machine-3" as expected.
3) I swap characters using this:

Code: Select all

/c local char = game.surfaces.nauvis.find_entities_filtered{name = "character", force = "player", limit = 1, position={4,3}, radius=2}[1]
game.player.set_controller{type=defines.controllers.character, character=char}
4) I print game.player.entity_copy_source again, this time it's nil.
5) I swap back to the first character:

Code: Select all

/c local char = game.surfaces.nauvis.find_entities_filtered{name = "character", force = "player", limit = 1, position={4,0}, radius=2}[1]
game.player.set_controller{type=defines.controllers.character, character=char}
4) I print game.player.entity_copy_source again,it is back to "assembling-machine-3".
Expected
Given that this is a property of LuaPlayer, I would expect this value to stay the same even when the player switches character.
Why
This is currently an annoyance in the Jetpack mod. Every time you take off or land, you lose your copy settings.

Re: LuaPlayer.entity_copy_source is actually associated to the character, not the player

Posted: Sat Jul 23, 2022 7:23 pm
by Rseding91
Thanks for the report however this is working correctly. "LuaPlayer" is simply a wrapper around some combination of: the character entity, the player object, and the controller the player is currently using.

However unrelated, I checked master and it was actually moved to the player object so when that's released it will work as you're wanting.