Make a leaderboard like Slither.io
Options
Hi, I'm trying to make a leaderboard that displays the top players scores like slither.io does. So far I have the players scores successfully being stored using Hashtable and CustomProperties, but I don't know how to display the scores. How do I compare the players scores, and should I use just one text (or string) to display it, or one text for each score I want displayed. Any help would be much appreciated! Thanks! P.S. I have looked at the other questions on here that ask similar things, but none seemed to have definitive answers.
0
Best Answer
-
Hi @jobo22,
you can iterate through PhotonNetwork.playerList and gather each player's score by accessing the CustomProperties where you have stored the score value. Gathered data can be stored in a local Hashtable or Dictionary for example (NickName and score value pair might be the best in this case). When having all the data collected you need to sort and display it somehow. Therefore you best check on the internet if there are any sorting algorithms that fit your needs.
Since doing this very often might have a bad influence on performance you can also use some of Photon's callbacks to handle this. For example OnPhotonPlayerConnected and OnPhotonPlayerDisconnected can be used to add or remove players from the local score board. OnPhotonPlayerPropertiesChanged can be used to update the score of a certain player on the score board. OnJoinedRoom can be used to create the local score board (hashtable or dictionary) for the first time.[...] but none seemed to have definitive answers.
In those cases we sadly can't provide definitive answers (or even complete solutions which work for everyone). However we try to give some hints how users can implement such features on their own.5
Answers
-
Hi @jobo22,
you can iterate through PhotonNetwork.playerList and gather each player's score by accessing the CustomProperties where you have stored the score value. Gathered data can be stored in a local Hashtable or Dictionary for example (NickName and score value pair might be the best in this case). When having all the data collected you need to sort and display it somehow. Therefore you best check on the internet if there are any sorting algorithms that fit your needs.
Since doing this very often might have a bad influence on performance you can also use some of Photon's callbacks to handle this. For example OnPhotonPlayerConnected and OnPhotonPlayerDisconnected can be used to add or remove players from the local score board. OnPhotonPlayerPropertiesChanged can be used to update the score of a certain player on the score board. OnJoinedRoom can be used to create the local score board (hashtable or dictionary) for the first time.[...] but none seemed to have definitive answers.
In those cases we sadly can't provide definitive answers (or even complete solutions which work for everyone). However we try to give some hints how users can implement such features on their own.5 -
@Christian_Simon Thank you for the answer, I think I'm figuring it out now!0