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.
Rename on_player_changed_position to on_character_changed_position?
-
- Long Handed Inserter
- Posts: 63
- Joined: Mon Oct 18, 2021 6:13 pm
- Contact:
Re: Rename on_player_changed_position to on_character_changed_position?
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.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.
Re: Rename on_player_changed_position to on_character_changed_position?
on_player_changed_position is correct.
-
- Long Handed Inserter
- Posts: 63
- Joined: Mon Oct 18, 2021 6:13 pm
- Contact:
Re: Rename on_player_changed_position to on_character_changed_position?
D'oh you're right, my mistake. I got confused by the documentation talking about players/characters as if they're different.
Re: Rename on_player_changed_position to on_character_changed_position?
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 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.
-
- Long Handed Inserter
- Posts: 63
- Joined: Mon Oct 18, 2021 6:13 pm
- Contact:
Re: Rename on_player_changed_position to on_character_changed_position?
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.
Re: Rename on_player_changed_position to on_character_changed_position?
Yes, but LuaPlayer.character can be nil, and there can be Character entities that are not controlled by any player.
-
- Long Handed Inserter
- Posts: 63
- Joined: Mon Oct 18, 2021 6:13 pm
- Contact:
Re: Rename on_player_changed_position to on_character_changed_position?
Is LuaPlayer.position a convenience method for LuaPlayer.character.position?
Re: Rename on_player_changed_position to on_character_changed_position?
Not reallyfredthedeadhead wrote: ↑Sun Oct 24, 2021 9:34 am Is LuaPlayer.position a convenience method for LuaPlayer.character.position?
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.
-
- Long Handed Inserter
- Posts: 63
- Joined: Mon Oct 18, 2021 6:13 pm
- Contact:
Re: Rename on_player_changed_position to on_character_changed_position?
Gotcha, thanks for the details! I understand better now, and I appreciate you taking the time to explain.