Skip to content

Instantly share code, notes, and snippets.

@xxshady
Last active June 21, 2024 18:38
Show Gist options
  • Save xxshady/45323eeb51559a97758922c441570709 to your computer and use it in GitHub Desktop.
Save xxshady/45323eeb51559a97758922c441570709 to your computer and use it in GitHub Desktop.
safe baseobject api concept
fn main(main_context: &MainContext) {
let _players: &[Player] = main_context.all_players();
every_tick(|ctx: &EveryTickContext| {
// cannot be called here
// main_context.all_players();
let _players: &[Player] = ctx.all_players();
// TODO: allow holding reference for unknown duration to player via Option?
let _player: Option<&Player> = ctx.get_player_by_id(1);
// not possible:
// spawn_future(async {
// dbg!(_players);
// dbg!(_player);
// });
});
let mut _players: &[Player] = &[];
on_server("some_event", |ctx: &OnServerEventContext| {
let _data: &Vec<u8> = &ctx.data;
let _players: &[Player] = ctx.all_players();
// wont work
// _players = players;
});
on_game_entity_create(|ctx: &GameEntityCreateContext| {
let _entity: &AnyEntity = &ctx.entity;
let _players: &[Player] = ctx.all_players();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment