--- title: 'loadScore' disqus: hackmd tags: 'so' --- ## **Read Leaderboard** How to read the data of the leaderboard one creates. Click Score. ![](https://i.imgur.com/DCqAuDK.jpg) Click GetLeaderBoard to check the leaderboard. ![](https://i.imgur.com/1LXtIhn.jpg) ``` C# using UnityEngine; using System.Collections; public class Sample_GetItemClass : MonoBehaviour { /******************************************************************* * Copyright © 2022 SPKITA Game Cloud. All Rights Reserved * *******************************************************************/ //enter the gguid shown in the developer backstage here private const string gguid = ""; //enter the Iguid shown in the developer backstage here private const string lguid = ""; // enter the verification shown in the developer backstage here byte[] certificate = {}; //declare CloudGame and this Class will be in charge of the communication with Cloud Server public CloudGame ag = null; string userAcc; //user’s account string userPwd; //user’s password void Start() { CloudSystem.UnityEnvironment(); CloudSystem.ServerProvider("sgc-api-us.spkita.com"); // set the server } void OnApplicationQuit() { //When the program is closed, the user’s account will not be logged out. Here we can add a mechanism that allows automatic logging out. if(ag!=null) ag.Dispose(); } public void LoginBtnClick() { userAcc = login_input_acc.text; userPwd = login_input_pwd.text; //the parameters needed when logging in, which are (account, password, gguid, certificate) ag = new CloudGame(userAcc, userPwd, gguid, certificate); //designate the way of management and start the detection on whether the connection is successful ag.onCompletion += CloudLaunch; ag.UnityLaunch(); } /******************************************************************* // After CloudGame finishes its execution, in CallBack there will be a message about whether the login is successful. // When the code is 0, the login succeeds and when the code is not 0, the login fails. // efer the errors in login to Error Code // *******************************************************************/ void CloudLaunch(int code, CloudGame game) { if (code == 0) { Debug.Log("Login Success! My poid : " + ag.poid + " NickName : " + ag.nickname); } else { Debug.LogWarning("Login Fail! Code : " + code); } } /******************************************************************* * Read Leaderboard *******************************************************************/ public void GetLeaderBoardBtn() { int type = 0; // 0: all the rankings, 1: daily ranking, 2: weekly ranking, 3: monthly ranking int ex = 0; // 0: current ranking CloudScore.GetLeaderBoard(ag, lguid, type, ex, CB_GetLeaderBoard, null); } /******************************************************************* // When the code is 0, the data-reading succeeds and when the code is not 0, it fails. *******************************************************************/ void CB_GetLeaderBoard(int code, object data, object token) { if (code == 0) { List<Hashtable> s = (List<Hashtable>)data; Debug.Log("s.Count = " + s.Count); if (s.Count == 0) // the data’s length is 0, which means there is no data { score_MsgText.text += "No Data!\n" ; return; } foreach (Hashtable node in s) { var nickname = node["nickname"]; var score = node["score"]; var stamp = node["stamp"]; score_MsgText.text += "nickname : " + nickname.ToString() + " , score : " + score.ToString() + " , stamp : " + stamp + "\n"; } } else { score_MsgText.text += "LoadLeaderBoard Fail! Code : " + code + "\n"; } } } ```