CREATE YOUR WORLD
Social
Leaderboard
18min
setting up a leaderboard the leaderboard is a module that provides functions for saving and managing each player's rankings and high scores step 1 create a leaderboard to create a leaderboard, select the \[get leaderboardinfo] button in projectsettings → zepeto → zepetoleaderboard menu select \[add leaderboard] to add a new leaderboard if there is a leaderboard that already exists, the leaderboard will appear on the settings screen step 2 customize a leaderboard the pop up window shown below will appear when the \[add leaderboard] button is selected you will be able to adjust each parameter values parameter description name leaderboard name update rule score update rules max score record the user's highest score min score record user's lowest score accumulate score add user's scores and save as a record resetinfo(s) you can set a period for the scores to reset \ this is helpful if the leaderboard needs to be updated every season \ the scores will not be reset by default, but you can make adjustments by setting reset periods (monthly, weekly, daily) step 3 set score reset score reset rules are as follows period description none scores will not reset day scores will reset daily at the set time (ex daily ranking) week scores will reset weekly on the set date and time (ex weekly ranking) month scores will reset monthly on the set date and time (ex monthly ranking; the max day value is 31, but if the month does not have 31 days, it will automatically adjust to the last day of the month) step 4 leaderboard id to use zepetoscript and leaderboard, you must have the leaderboard id information to access the leaderboard information, you can go to settings (under edit in the project settings menu, go to zepeto → zepeto leaderboard → edit), or load from zepetoscript api once the reset rule is set, the leaderboard cannot be modified to change the reset rule, you must create a new leaderboard reset time is based on utc+0 offset will be provided so that the time zone can be changed in the future recording score leaderboardapi setscore() is an api that records the user's score on the leaderboard leaderboard id, score value, the point of completion and the point of error are passed as an argument user information for the score will automatically be saed the following is an example for loading the leaderboardapi setscore function leaderboardapi setscore(this leaderboardid, this score, this onresult, this onerror); the following is the code template for retrieving the user's score to the leaderboard import { zepetoscriptbehaviour } from 'zepeto script'; import { setscoreresponse, leaderboardapi } from 'zepeto script leaderboard'; export default class setscoreexample extends zepetoscriptbehaviour { public leaderboardid string; public score number; start() { leaderboardapi setscore(this leaderboardid, this score, this onresult, this onerror); } onresult(result setscoreresponse) { console log(`result issuccess ${result issuccess}`); } onerror(error string) { console error(error); } } searching ranking details get ranking information in a specific range use the leaderboardapi getrangerank() function to load a specific range of ranking details the boolean value to retrieve leaderboard id, start ranking, last ranking, reset rule and last season's ranking information, and the callback function from the time of completion and time of error occurrence is passed as an argument user information that inquires ranking information is automatically entered, and up to 100 ranking information can be processed per inquiry (ex paging in 1 100, 101 200 format for implementation) ❗️ caution if more than 100 data are loaded at a time, it may not work properly due to api load issues and rate limits example function call an example of calling leaderboardapi getrangerank() function is as follows leaderboardapi getrangerank(this leaderboardid, this startrank, this endrank, this resetrule, false, this onresult, this onerror); the following code is an example for loading a specific range of ranking information you can use the member value from onresult to load the profile photo 📘 please refer to the following guide \[ user information docid\ lyicyvjyqztqnkwbng2uu ] import { zepetoscriptbehaviour } from 'zepeto script'; import { getrangerankresponse, leaderboardapi, resetrule } from 'zepeto script leaderboard'; export default class getrangerankexample extends zepetoscriptbehaviour { public leaderboardid string; public startrank number; public endrank number; public resetrule resetrule; start() { leaderboardapi getrangerank(this leaderboardid, this startrank, this endrank, this resetrule, false, this onresult, this onerror); } onresult(result getrangerankresponse) { console log(`result issuccess ${result issuccess}`); if (result rankinfo myrank) { console log(`member ${result rankinfo myrank member}, rank ${result rankinfo myrank rank}, 	 score ${result rankinfo myrank score}, name ${result rankinfo myrank name}`); } if (result rankinfo ranklist) { for (let i = 0; i < result rankinfo ranklist length; ++i) { const rank = result rankinfo ranklist get item(i); console log(`i ${i}, member ${rank member}, rank ${rank rank}, score ${rank score}, name ${rank name}`); } } } onerror(error string) { console error(error); } } searching leaderboard details search all leaderboards use the leaderboardapi getallleaderboards function to load all leaderboard information in the specified world the callback function from the time of completion to the time of error occurrence is passed as an argument an example of loading leaderboardapi getallleaderboards function is as follows leaderboardapi getallleaderboards(this onresult, this onerror); the following is an example for loading the entire leaderboard information import { zepetoscriptbehaviour } from 'zepeto script'; import { getallleaderboardsresponse, leaderboardapi } from 'zepeto script leaderboard'; export default class getallleaderboardexample extends zepetoscriptbehaviour { start() { leaderboardapi getallleaderboards(this onresult, this onerror); } onresult(result getallleaderboardsresponse) { console log(`result issuccess ${result issuccess}`); if (result leaderboards) { for (let i = 0; i < result leaderboards length; ++i) { const leaderboard = result leaderboards\[i]; console log(`i ${i}, id ${leaderboard id}, name ${leaderboard name}`); } } } onerror(error string) { console error(error); } } search specific leaderboards use the leaderboardapi getleaderboardsfunction to load specific leaderboard information the callback function for the leaderboard id, the time of completion, the time of error occurrence are passed as an argument an example of loading leaderboardapi getleaderboard function is as follows leaderboardapi getleaderboard(this leaderboardid, this onresult, this onerror); the following is an example for loading certain leaderboard inofrmation import { zepetoscriptbehaviour } from 'zepeto script'; import { getleaderboardresponse, leaderboardapi } from 'zepeto script leaderboard'; export default class getleaderboardexample extends zepetoscriptbehaviour { public leaderboardid string; start() { leaderboardapi getleaderboard(this leaderboardid, this onresult, this onerror); } onresult(result getleaderboardresponse) { console log(`result issuccess ${result issuccess}`); if (result leaderboard) { console log(`id ${result leaderboard id}, name ${result leaderboard name}`); } } onerror(error string) { console error(error); } } leaderboard usage example the following is an example of a leaderboard applied to the official zepeto world slime party by setting, reading, and utilizing api calls to fetch rankings within a specific range, you can structure it as follows in the ui