Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

Is there any easy way to create a leaderboard for Hololens?

I'm developing a small game for Hololens and now i have to make a leader board featuring players' score.
The game will played by one player at a time so I only have to insert the player's id and score once the game is over.
The leader board will be shown and the text in it must be a list of the first 10 players with the highest scores.
I was just wondering if I need a database in order to make values persistent even after quitting the game or turning off the device.

Best Answer

Answers

  • Options
    keljedkeljed ✭✭
    Answer ✓

    I think for a simple game it is good enough to save the score data in a xml file. There are a lot possibilities how to do this. This one might be a good starting point:

    http://wiki.unity3d.com/index.php?title=Saving_and_Loading_Data:_XmlSerializer

  • Options

    @keljed said:
    I think for a simple game it is good enough to save the score data in a xml file. There are a lot possibilities how to do this. This one might be a good starting point:

    http://wiki.unity3d.com/index.php?title=Saving_and_Loading_Data:_XmlSerializer

    what if I use PlayerPrefs?

  • Options

    @angelicaHolo I don't know, I haven't used that before. It sounds like a simple KeyValueSettings file. If you can use that on the HoloLens you should be able to serialize your leader board as JSON and store it in the PlayerPrefs.

  • Options

    Player prefs should work.

    Also you may want to check out: https://docs.unity3d.com/ScriptReference/Social.html and use Unity3D's built in leaderboard which I think will default to local if you do not integrate with a backend but I am not certain.

    Taqtile

  • Options

    @mark_grossnickle hey there. I tried using Player Prefs but when i tried the game on the hololens, it didn't work. When I closed the application and re-open it, the highest score wasn't there. it must be code problem.

  • Options

    i solved the leader board problem :) thanks guys

  • Options

    What was your solution? (for future posters)

    Taqtile

  • Options

    PlayerPrefs in the end. It works fine in the end

  • Options
    edited April 2017

    This is my leader board code:
    It saves only 3 scores.

    in the start method I create the keys and set their values to a minimum score and the orderScores is called when my timer is over.

    `
    public void Start()
    {
    if (!(PlayerPrefs.HasKey("TopPlayer") && PlayerPrefs.HasKey("SecondScore") && PlayerPrefs.HasKey("ThirdScore")))
    {
    PlayerPrefs.SetInt("TopPlayer", 0);
    PlayerPrefs.SetFloat("TopScore", 2);

            PlayerPrefs.SetInt("SecondPlayer", 0);
            PlayerPrefs.SetFloat("SecondScore", 1);
    
            PlayerPrefs.SetInt("ThirdPlayer", 0);
            PlayerPrefs.SetFloat("ThirdScore", 0.5f);
    
            PlayerPrefs.SetInt("CurrentPlayer", 0);
            PlayerPrefs.SetFloat("CurrentScore", 0);
            PlayerPrefs.Save();
        }
        GameManager.Instance.highScore = PlayerPrefs.GetFloat("TopScore");
    
        if (!(PlayerPrefs.HasKey("CurrentPlayer")))
        {
            PlayerPrefs.SetInt("CurrentPlayer", 0);
            PlayerPrefs.Save();
        }
        temp = PlayerPrefs.GetInt("CurrentPlayer") + 1;
        PlayerPrefs.SetInt("CurrentPlayer", temp);
        PlayerPrefs.Save();
    
        Debug.Log(PlayerPrefs.GetInt("CurrentPlayer"));
    }
    
    public void orderScores()
    {
        if ((GameManager.Instance.currentScore > PlayerPrefs.GetFloat("ThirdScore")) && (GameManager.Instance.currentScore < PlayerPrefs.GetFloat("SecondScore")))
        {
            Debug.Log("sono primo if");
            PlayerPrefs.SetInt("ThirdPlayer", PlayerPrefs.GetInt("CurrentPlayer"));
            PlayerPrefs.SetFloat("ThirdScore", GameManager.Instance.currentScore);
            PlayerPrefs.Save();
        }
        else
        {
            if ((GameManager.Instance.currentScore > PlayerPrefs.GetFloat("SecondScore")) && (GameManager.Instance.currentScore < PlayerPrefs.GetFloat("TopScore")))
            {
                Debug.Log("sono dentro if 2");
                PlayerPrefs.SetInt("ThirdPlayer", PlayerPrefs.GetInt("SecondPlayer"));
                PlayerPrefs.SetFloat("ThirdScore", PlayerPrefs.GetFloat("SecondScore"));
    
                PlayerPrefs.SetInt("SecondPlayer", PlayerPrefs.GetInt("CurrentPlayer"));
                PlayerPrefs.SetFloat("SecondScore", GameManager.Instance.currentScore);
                PlayerPrefs.Save();
            }
        }
    
        if (GameManager.Instance.currentScore > PlayerPrefs.GetFloat("TopScore"))
        {
            Debug.Log("sono dentro if 3");
            /*PlayerPrefs.DeleteKey("ThirdPlayer");
            PlayerPrefs.DeleteKey("ThirdScore");*/
            PlayerPrefs.SetInt("ThirdPlayer", PlayerPrefs.GetInt("SecondPlayer"));
            PlayerPrefs.SetFloat("ThirdScore", PlayerPrefs.GetFloat("SecondScore"));
    
            PlayerPrefs.SetInt("SecondPlayer", PlayerPrefs.GetInt("TopPlayer"));
            PlayerPrefs.SetFloat("SecondScore", PlayerPrefs.GetFloat("TopScore"));
    
            PlayerPrefs.SetInt("TopPlayer", PlayerPrefs.GetInt("CurrentPlayer"));
            PlayerPrefs.SetFloat("TopScore", GameManager.Instance.currentScore);
            PlayerPrefs.Save();
    
            GameManager.Instance.highScore = PlayerPrefs.GetFloat("TopScore");
        }
    }
    

    `

Sign In or Register to comment.