Rename on_player_changed_position to on_character_changed_position?

Things that we aren't going to implement
Post Reply
fredthedeadhead
Inserter
Inserter
Posts: 28
Joined: Mon Oct 18, 2021 6:13 pm
Contact:

Rename on_player_changed_position to on_character_changed_position?

Post by fredthedeadhead »

The event on_player_changed_position provides a player_index, but it's not the player that's updated - it's the player's character.

To be more accurate, the event should be called on_character_changed_position, which should provide the same parameters (for convenience), plus the unit_number of character that moved.

If it's too big of a breaking change though, as a compromise, can unit_number of the moved character be added to on_player_changed_position?

I ask because I when a character moves, I only want to perform an action for that character, and I can't tell which character has changed position. Although I suspect that it's exceedingly rare for a player to have more than one character? I'm confused by the method LuaPlayer.get_associated_characters() - and I want to be thorough in responding to character updates.

curiosity
Filter Inserter
Filter Inserter
Posts: 322
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Rename on_player_changed_position to on_character_changed_position?

Post by curiosity »

fredthedeadhead wrote:
Wed Oct 20, 2021 7:25 pm
The event on_player_changed_position provides a player_index, but it's not the player that's updated - it's the player's character.
Aside from the rename being a cosmetic breaking change and therefore extremely unlikely to happen, this is just plain wrong. Players have position. The event works fine on characterless players.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2241
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Rename on_player_changed_position to on_character_changed_position?

Post by boskid »

on_player_changed_position is correct.

fredthedeadhead
Inserter
Inserter
Posts: 28
Joined: Mon Oct 18, 2021 6:13 pm
Contact:

Re: Rename on_player_changed_position to on_character_changed_position?

Post by fredthedeadhead »

D'oh you're right, my mistake. I got confused by the documentation talking about players/characters as if they're different.

curiosity
Filter Inserter
Filter Inserter
Posts: 322
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Rename on_player_changed_position to on_character_changed_position?

Post by curiosity »

fredthedeadhead wrote:
Thu Oct 21, 2021 10:41 pm
D'oh you're right, my mistake. I got confused by the documentation talking about players/characters as if they're different.
Players and characters are different. Player is the controlling entity (i.e. you), character is the entity in the world that the player is bound to.

fredthedeadhead
Inserter
Inserter
Posts: 28
Joined: Mon Oct 18, 2021 6:13 pm
Contact:

Re: Rename on_player_changed_position to on_character_changed_position?

Post by fredthedeadhead »

curiosity wrote:
Fri Oct 22, 2021 7:38 am
Players and characters are different. Player is the controlling entity (i.e. you), character is the entity in the world that the player is bound to.
Sorry yes, they're different, but when it comes to position they're the same right? LuaPlayer.position and LuaPlayer.character.position return the same value.

posila
Factorio Staff
Factorio Staff
Posts: 5201
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Rename on_player_changed_position to on_character_changed_position?

Post by posila »

Yes, but LuaPlayer.character can be nil, and there can be Character entities that are not controlled by any player.

fredthedeadhead
Inserter
Inserter
Posts: 28
Joined: Mon Oct 18, 2021 6:13 pm
Contact:

Re: Rename on_player_changed_position to on_character_changed_position?

Post by fredthedeadhead »

Is LuaPlayer.position a convenience method for LuaPlayer.character.position?

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Rename on_player_changed_position to on_character_changed_position?

Post by Klonan »

fredthedeadhead wrote:
Sun Oct 24, 2021 9:34 am
Is LuaPlayer.position a convenience method for LuaPlayer.character.position?
Not really

When the player is attached to a character, the player object is set to the characters position each tick,
But for instance if the player is a different controller, a ghost, spectator, god, cutscene, etc., then the position is the players position.

Character is an entity, it can exist with or without a Player.
Player is a object that players control, it can exist with or without a character.

The event in question specifically only related to player movement, when the player is controlling a character, they are the same value.

But for characters without players, the event is not fired when that character moves.
When a player without a character moves, the event is fired.

Therefore the event and naming is all correct, it is when a player moves, regardless of any character or other controller status.

fredthedeadhead
Inserter
Inserter
Posts: 28
Joined: Mon Oct 18, 2021 6:13 pm
Contact:

Re: Rename on_player_changed_position to on_character_changed_position?

Post by fredthedeadhead »

Gotcha, thanks for the details! I understand better now, and I appreciate you taking the time to explain.

Post Reply

Return to “Won't implement”