question

manolhsplaths46 avatar image
manolhsplaths46 asked

Unity3d,trying to make a leaderboard,show up the statistics in UI.text,Unity3d ,trying to make leaderboard statics appear on UI.text

So i want to display on the UI.text for example this text:
public Text myDisplayText;

This function :print (value.StatValue + " " + value.DisplayName);

I am trying to do it like this but it is not working:

myText.text = value.StatValue + " " + value.DisplayName;

i get an error : NullReferenceException: Object reference not set to an instance of an object


If you notice yeah this is a leaderboard and it prints for example: User:test score:150 and i want to make a leaderboard if i can find how to convert to UI .text it would be great then i can figure out on how to do it.

   public void GetLeaderboard()
     {
      var request = new GetLeaderboardRequest();
      request.StartPosition = 0;
      request.StatisticName = "Coins";
      PlayFabClientAPI.GetLeaderboard(request, OnLeaderboardSuccess, OnPlayFabError);
     }
     private void OnLeaderboardSuccess(GetLeaderboardResult obj)
     {
      foreach(var value in obj.Leaderboard)
      {
      print(value.StatValue + " " + value.DisplayName);
      }
     }
,

So i want to display on the UI.text for example this text:
public Text myDisplayText;

This function :print (value.StatValue + " " + value.DisplayName);

I am trying to do it like this but it is not working:

myText.text = value.StatValue + " " + value.DisplayName;

i get an error : NullReferenceException: Object reference not set to an instance of an object


If you notice yeah this is a leaderboard and it prints for example: User:test score:150 and i want to make a leaderboard if i can find how to convert to UI .text it would be great then i can figure out on how to do it.

   public void GetLeaderboard()
     {
      var request = new GetLeaderboardRequest();
      request.StartPosition = 0;
      request.StatisticName = "Coins";
      PlayFabClientAPI.GetLeaderboard(request, OnLeaderboardSuccess, OnPlayFabError);
     }
     private void OnLeaderboardSuccess(GetLeaderboardResult obj)
     {
      foreach(var value in obj.Leaderboard)
      {
      print(value.StatValue + " " + value.DisplayName);
      }
     }

unity3dLeaderboards and Statistics
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JayZuo avatar image
JayZuo answered

In your code, I didn't see how you set "myText" and that's might be why you got a "NullReferenceException". The code you've posted to get leaderboard is right. So the problem here is a Unity 3D problem about how to create a item list with Unity UI. There are lots of tutorials online, for example: https://www.youtube.com/watch?v=ZI6DwJtjlBA and http://www.folio3.com/blog/creating-dynamic-scrollable-lists-with-new-unity-canvas-ui/. Generally, you will create a prefab for Text UI, instantiate the prefab dynamically and then put them into some panel.

Besides, as this is a Unity UI question, I'd suggest you post on Unity forums for further help.

7 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

manolhsplaths46 avatar image manolhsplaths46 commented ·

i declare it like public Text myText;

0 Likes 0 ·
JayZuo avatar image JayZuo ♦ manolhsplaths46 commented ·

But how did you initialize "myText"? Have you set a instance to it either in Inspector or in script?

0 Likes 0 ·
manolhsplaths46 avatar image manolhsplaths46 JayZuo ♦ commented ·

i drag and drop it there like i have to ... but maybe i dont know it doesn't get the reference for some reason?

0 Likes 0 ·
Show more comments
JayZuo avatar image JayZuo ♦ manolhsplaths46 commented ·

You may try to just set a test string to "myText" like: myText.text = "test" to see if it works.

0 Likes 0 ·
manolhsplaths46 avatar image manolhsplaths46 JayZuo ♦ commented ·

yep that work but i have another question how can i access from leaderboard the statvalue (The score) ? at the moment i am using a foreach method but i would like to access those values from outside the leaderboard if that makes sense:


public void GetLeaderboard() { var request = new GetLeaderboardRequest(); request.StartPosition = 0; request.StatisticName = "Coins"; PlayFabClientAPI.GetLeaderboard(request, OnLeaderboardSuccess, OnPlayFabError); } private void OnLeaderboardSuccess(GetLeaderboardResult obj) { foreach(var value in obj.Leaderboard) { print(value.StatValue + " " + value.DisplayName); myText.text = value.StatValue + " " + value.DisplayName; } } private void OnPlayFabError(PlayFabError obj) { print("Es ist etwas im Stats-Skript schief gelaufen"); } public void DEBUG_ADD_KILL_TO_QUILL() { ChangeScore(HowtoPutHere.ValueDisplayName, "kills", HowtoPutHere.ValueStatvalue); }
0 Likes 0 ·
Show more comments
Jaun Mark avatar image
Jaun Mark answered

Go to Edit > Project Settings > Localization to get to the Localization Settings. Unity will prompt you to build a settings Item if one does not exist. The Asset section also helps to build the settings File. Select Assets > Create > Localization > Localization Settings from the drop-down menu https://mmcgbl.com/node-js-development-company/

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]