Elem08
9 months agoMember
Can't get or set VariableGroup variables
Hello!
I am extremely new to development (using the Desktop Editor), and I wanted to try a quick world that just enables a button that, when pressed, updates a player's score using NetworkBroadcastEvents and Variable Groups. Here's what I've got:
A VariableGroup called `PlayerAttributes` with `test` and `localScore`
Which I then try to reference in a Typescript file:
// names of the variable group and persistent variable containing player data
const varGroupName: string = "PlayerAttributes";
const varName: string = "localScore"; // Set as a Number
const varKey: string = `${varGroupName}:${varName}`;
export type ButtonPressedType = {
player: Player
}
class ScoreManager extends hz.Component<typeof ScoreManager> {
static propsDefinition = {};
start() {
this.connectNetworkBroadcastEvent(NetworkEvents.buttonPressed, (data: ButtonPressedType) => {
console.log('Button pressed by player', data.player.id);
const curScore = Number(this.world.persistentStorage.getPlayerVariable(data.player, 'PlayerAttributes:localScore'));
console.log('Current score:', curScore)
this.world.persistentStorage.setPlayerVariable(data.player, 'PlayerAttributes:localScore', curScore + 1)
console.log('Player', data.player.id, 'score:', curScore + 1)
})
}
}
hz.Component.register(ScoreManager);
But every time I send the network event, I get the following:
Can't set value for PlayerAttributes:localScore. PlayerAttributes:localScore was deleted or never existed. Go to Systems tab in creation UI to confirm.
What am I doing wrong?
It's a known bug. Hopefully it gets resolved soon