"Leaderboards" Scripting/Making World Leaderboards. A Meta Horizon Worlds Tutorial.

4 min read 5 months ago
Published on Aug 02, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

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

  1. Open Build Mode

    • Access your build menu and select Gizmos.
  2. Add a Script Gizmo

    • Drag out a script gizmo and name it WorldVisits with the identifier lb for leaderboard.
  3. 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.
  4. Create Player Persistent Variable for Visits

    • Navigate to Systems, then Player Variables, and create a variable named Visits.
  5. Create Leaderboard Variable for Visits

    • In the leaderboards section, create a leaderboard named Visits with a descending order.
  6. Configure the Script

    • Ensure the player persistent variable is set to Visits and add a +1 operator to increment the visits count.
  7. Set Leaderboard Score

    • Use the Set World Leaderboard Score for Player action to link the visits variable to the leaderboard.
  8. 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.

Step 2: Create a Leaderboard for Time Spent in World

  1. Add a New Script Gizmo

    • Open the build menu and add another script gizmo, naming it TimeSpent and adding lb for leaderboard.
  2. Set Timer for Tracking Time

    • Use the When World is Started event to send an event that starts a timer.
  3. Add Player Entry Event

    • Include the When Player Enters World event and create a player list variable to track individual players.
  4. 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.
  5. Remove from List on Exit

    • Set up the When Player Exits World event to remove the player from the list if they exist.
  6. Track Time with a Loop

    • Use a loop to check each player’s time every minute (or adjust to a shorter duration for testing).
  7. Create Player Persistent Variable for Minutes

    • Create a variable named MinutesInWorld to track the time spent.
  8. Set Leaderboard for Time Spent

    • Establish a leaderboard for time spent in the world, ensuring it is set to descending order.
  9. 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)

  1. Add a Script for the Basketball Game

    • Pull out a script gizmo and name it BasketballGame with lb for leaderboard.
  2. Set Up Trigger Event

    • Use the When Trigger is Entered by Object event to track when the basketball enters the hoop.
  3. Add Player Persistent Variable for Score

    • Create a variable called BBallScore to keep track of the player's score.
  4. Set Score Increment Logic

    • Every time the trigger is entered, set the player’s persistent variable to increment their score by 1.
  5. Configure Leaderboard for Scores

    • Create a leaderboard named BBallGame and ensure it is in descending order.
  6. Attach to Trigger

    • Place the trigger in the game area, ensuring it is set to react to objects tagged as "throwable".
  7. 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!