Page 1 of 1

Rename on_player_changed_position to on_character_changed_position?

Posted: Wed Oct 20, 2021 7:25 pm
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.

Re: Rename on_player_changed_position to on_character_changed_position?

Posted: Wed Oct 20, 2021 8:17 pm
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.

Re: Rename on_player_changed_position to on_character_changed_position?

Posted: Thu Oct 21, 2021 8:31 am
by boskid
on_player_changed_position is correct.

Re: Rename on_player_changed_position to on_character_changed_position?

Posted: Thu Oct 21, 2021 10:41 pm
by fredthedeadhead
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?

Posted: Fri Oct 22, 2021 7:38 am
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.

Re: Rename on_player_changed_position to on_character_changed_position?

Posted: Fri Oct 22, 2021 8:33 am
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.

Re: Rename on_player_changed_position to on_character_changed_position?

Posted: Fri Oct 22, 2021 9:14 am
by posila
Yes, but LuaPlayer.character can be nil, and there can be Character entities that are not controlled by any player.

Re: Rename on_player_changed_position to on_character_changed_position?

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

Re: Rename on_player_changed_position to on_character_changed_position?

Posted: Sun Oct 24, 2021 12:21 pm
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.

Re: Rename on_player_changed_position to on_character_changed_position?

Posted: Wed Nov 03, 2021 6:55 pm
by fredthedeadhead
Gotcha, thanks for the details! I understand better now, and I appreciate you taking the time to explain.