setBucketValue
Saves a value to a Bucket.
All values are stored as strings.
Signatures
beacon.setBucketValue(bucketId, key, value);
beacon.setBucketValue(bucketId, key, value, playerId);
Parameters
bucketId
The UUID of the bucket to save a value to.
key
They key of the value to save.
value
The value to save.
playerId
Include this parameter to save the value for this player. Otherwise saves the value to the non-player scope.
Examples
Increment player kill count when a player dies to another player
const victimId = beacon.eventData.characterId;
const attacker = beacon.eventData.attacker;
const bucketId = 'd7c0eee0-17bd-495d-88f6-16a815c36587';
if (attacker.kind === 'player') {
const attackerId = attacker.characterId;
const attackerCharacter = beacon.fetchCharacter(attackerId);
const attackerPlayerId = attackerCharacter.playerId;
const killCount = parseInt(beacon.getBucketValue(bucketId, 'killCount', attackerPlayerId) ?? 0);
beacon.setBucketValue(bucketId, 'killCount', attackerPlayerId, killCount + 1);
}
Because getBucketValue
returns a string, we need to use parseInt
to convert the string to a number. If the player has no value yet, the function will return null, so the null-coalescing operator (??
) allows falling back to 0 instead.