"Leaderboards" Scripting/Making World Leaderboards. A Meta Horizon Worlds Tutorial.
Table of Contents
Introduction
In this tutorial, you'll learn how to create and script world leaderboards in Meta Horizon Worlds. We will cover three types of leaderboards: tracking world visits, time spent in the world, and scores from a basketball game. This guide will help you implement these features effectively.
Step 1: Create a Leaderboard for World Visits
-
Open Build Mode
- Access your build menu and select Gizmos.
-
Add a Script Gizmo
- Drag out a script gizmo and name it
WorldVisits
with the identifierlb
for leaderboard.
- Drag out a script gizmo and name it
-
Set Player Entry Event
- Go to player events and select
When Player Enters World
. - Add an action to set the player’s persistent variable to
+1
.
- Go to player events and select
-
Create Player Persistent Variable for Visits
- Navigate to Systems, then Player Variables, and create a variable named
Visits
.
- Navigate to Systems, then Player Variables, and create a variable named
-
Create Leaderboard Variable for Visits
- In the leaderboards section, create a leaderboard named
Visits
with a descending order.
- In the leaderboards section, create a leaderboard named
-
Configure the Script
- Ensure the player persistent variable is set to
Visits
and add a+1
operator to increment the visits count.
- Ensure the player persistent variable is set to
-
Set Leaderboard Score
- Use the
Set World Leaderboard Score for Player
action to link the visits variable to the leaderboard.
- Use the
-
Attach to World Leaderboard Gizmo
- Open the properties of the world leaderboard gizmo and set its leaderboard to the
Visits
leaderboard, with the title "Most Visits". - Adjust the number of entries per page and set the display to dark mode.
- Open the properties of the world leaderboard gizmo and set its leaderboard to the
Step 2: Create a Leaderboard for Time Spent in World
-
Add a New Script Gizmo
- Open the build menu and add another script gizmo, naming it
TimeSpent
and addinglb
for leaderboard.
- Open the build menu and add another script gizmo, naming it
-
Set Timer for Tracking Time
- Use the
When World is Started
event to send an event that starts a timer.
- Use the
-
Add Player Entry Event
- Include the
When Player Enters World
event and create a player list variable to track individual players.
- Include the
-
Implement Conditional Logic for Player List
- Use an
If
statement to check if the player is not in the list and add them if they aren’t.
- Use an
-
Remove from List on Exit
- Set up the
When Player Exits World
event to remove the player from the list if they exist.
- Set up the
-
Track Time with a Loop
- Use a loop to check each player’s time every minute (or adjust to a shorter duration for testing).
-
Create Player Persistent Variable for Minutes
- Create a variable named
MinutesInWorld
to track the time spent.
- Create a variable named
-
Set Leaderboard for Time Spent
- Establish a leaderboard for time spent in the world, ensuring it is set to descending order.
-
Attach to World Leaderboard Gizmo
- Link the script to a new world leaderboard gizmo with the title "Most Time Spent" and set it to display 10 entries in dark mode.
Step 3: Create a Leaderboard for Scores (Basketball Game)
-
Add a Script for the Basketball Game
- Pull out a script gizmo and name it
BasketballGame
withlb
for leaderboard.
- Pull out a script gizmo and name it
-
Set Up Trigger Event
- Use the
When Trigger is Entered by Object
event to track when the basketball enters the hoop.
- Use the
-
Add Player Persistent Variable for Score
- Create a variable called
BBallScore
to keep track of the player's score.
- Create a variable called
-
Set Score Increment Logic
- Every time the trigger is entered, set the player’s persistent variable to increment their score by 1.
-
Configure Leaderboard for Scores
- Create a leaderboard named
BBallGame
and ensure it is in descending order.
- Create a leaderboard named
-
Attach to Trigger
- Place the trigger in the game area, ensuring it is set to react to objects tagged as "throwable".
-
Attach to World Leaderboard Gizmo
- Link the scoring script to a world leaderboard gizmo with the title "Most Shots Made", configuring it to display scores dynamically.
Conclusion
You have successfully created three types of leaderboards in Meta Horizon Worlds: for tracking world visits, time spent, and scores in a basketball game. These features enhance user engagement and provide a competitive edge in your virtual world. Explore further customization options and consider integrating additional gameplay elements to make your world even more interactive!