Skip to main content

6 replies

gausroth
Honored Contributor
February 26, 2025

If the UI is not a local script you get the PPV like you would normally would then set a binding with that value. What exactly are you trying to make? I'll post a code example if the desktop editor ever lets me in.

GitHub: https://github.com/Gausroth/HorizonWorldsTutorials.git Discord: https://discord.gg/hNyDQwdw4N YouTube: https://www.youtube.com/@GausRothTutorials
WolfMaNeMattOfficial
Up and Coming
February 26, 2025

Ex: UI displays ppv in right corner of ui, interface consist of an add button that adds towards current ppv

protoxr1487653
Honored Contributor
February 26, 2025

These can be accessed the same way as within a normal component and should follow the same practice of saving the PPV to a variable, then using that variable as the reference.

 

const example: number = this.world.persistentStorage.getPlayerVariable(player, 'Group:PPV');

 

If you need the UI to update you would still use a normal binding and not the PPV, then Set that binding to a new value to force a UI update. In fact you would not want to update the PPV very often, perhaps only at the end of the game loop.

 

const score: Binding<number> = new Binding<number>(example);

 

After that to display this PPV on the custom UI, I would point you towards the custom UI tutorial where they explain how to use the Text UI Node in the first lesson on your left after entering the world.

https://developers.meta.com/horizon-worlds/learn/documentation/tutorial-worlds/custom-ui-examples-tutorial/station-1-text-and-fonts

Edit: If you want a button instead of text you will need to work your way to lesson 5 where they discuss the Pressable UI Node where the onClick callback would change the PPV then the binding to update the UI.

https://developers.meta.com/horizon-worlds/learn/documentation/tutorial-worlds/custom-ui-examples-tutorial/station-5-light-the-sphere-dialog

Proto_XR
WolfMaNeMattOfficial
Up and Coming
February 26, 2025

Awesome

gausroth
Honored Contributor
February 26, 2025

It would look something like this. I left the styles blank because I don't know what it should look like.

private ppvText = new Binding<string>('PPV Value');

initializeUI() {
     return View({
          children: [
               Text({
                    text: this.ppvText,
                    style: {},
               }),
               Pressable({
                    children: [
                         Text({
                              text: "Press Me",
                              style: {},
                         }),
                    ],
                    onPress: (player: Player) => { SetPPVText(player) },
                    style: {},
               }),
          ],
          style: {},
     })
}

SetPPVText(player: Player){
// if this script is a local script you will have to get this value from somewhere else.
// get the players ppv value
let ppvValue = this.world.persistentStorage.getPlayerVariable(player, 'Variable Group Name:Variable Name');
// increase the value by 1
ppvValue += 1;
// set the players ppv to the new value
this.world.persistentStorage.setPlayerVariable(player, 'Variable Group Name:Variable Name', ppvValue)
// set the the ui text binding to the new value
this.ppvText.set(ppvValue)
}

 

GitHub: https://github.com/Gausroth/HorizonWorldsTutorials.git Discord: https://discord.gg/hNyDQwdw4N YouTube: https://www.youtube.com/@GausRothTutorials
WolfMaNeMattOfficial
Up and Coming
February 28, 2025

Thank You