PlayerData: delete() method
Available since
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe delete() method of the PlayerData interface deletes a key and resolves with whether it existed.
Syntax
delete(key)
delete(key, options)
Parameters
key- The key, 1 to 64 of
A-Z a-z 0-9 _ . : -. optionsOptional-
An object with any of these properties:
version- The version the key must have, or the delete fails with
E_VERSION. once- A key that makes the delete safe to repeat, as for
set().
Return value
A Promise that resolves with true if the key existed, or false.
Exceptions
The promise rejects with a DataError, such as E_VERSION when the key doesn’t have the version given.
Examples
Using up a one-time pass
// pass.ts
import { defineRoom } from "@irtio/room";
export default defineRoom({
async onJoin(room, connection) {
const hadPass = await room.playerData(connection.player).delete("arena-pass");
if (!hadPass) room.kick(connection, "you need an arena pass");
},
});
See also
Runtime availability
| Hosted rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
delete() | 0.1 | 0.1 | 0.1 | 0.1 |