Skip to content

Users and players

Compiles

Two words that sound alike mean different things:

let me: User = $user.get_primary()
let body: Entity = $catch.get_player_entity(me)

$user.get_primary() is the main user playing on this machine. $catch.get_player_entity gives the root entity of a user’s player.

Anything in the world can have an owner. A player’s entities are owned by its user, and so are things they spawn:

fn owner_name(thing: Entity) -> string {
let user: User = $entity.get_owning_user_from_entity(thing)
return $user.get_name(user, false)
}

A trigger reports the component that overlapped it, and that’s usually a collider on some child of the player, not the player’s root. Search the hierarchy for catch_player:

  • playercatch_playerplayer_movementtransform
    • body
      • collider…this is what overlapped
An illustration: what overlaps a trigger is often a child deep inside the player, and its hierarchy leads back to catch_player.
event export fn trigger_overlapped(other, unused) {
if !other {
return
}
let touched: Entity = $component.get_entity(other)
let player: Component = $entity.get_hierarchy_singleton("catch_player.vscript", touched)
if !player {
return // not a player: a ball, perhaps
}
let user: User = $entity.get_owning_user_from_entity($component.get_entity(player))
$debug.print_line("{} stepped on me", [$user.get_name(user, false)], false)
}
let everyone: list = $user.get_all_users()
for i in 0..everyone.len() {
let user: User = everyone.get(i)
$debug.print_line("{}", [$user.get_name(user, false)], false)
}

$user.is_local(user) tells you whether a user plays on this machine; use it to show something only to the player it concerns.

For programmers

User is a value handle; compare two with $user.compare_users (0 when equal). $entity.get_owning_user() is the calling component’s owner. Bots are users too.