[Huawei Developers] shikkerimath:
View attachment 5214007

Introduction

Hello everyone, this article is third part of the Huawei Game Service blog series. In the third part, I’ve give some detail about Game Service and I’ve give information about leaderboards and saved games. Also I've explain how to use it in the your mobile game app with the MVVM structure. You can find second part of the Game Service blog series on the below.

How to Use Game Service with MVVM / Part 2— Achievements & Events

What Is Leaderboards?

Leaderboards are an effective way to drive competition among game players by displaying players’ rankings. You can create up to 70 leaderboards in AppGallery Connect. Your game can report the score of a player to one or more leaderboards you have created at specified moments (for example, when a player reaches a level or a round ends). Huawei game server automatically processes the scores of players and ranks them. Then you can call rankings APIs to display the leaderboards to your game players.

The basic functions of a leaderboard are as follows:

Huawei game server automatically checks whether a reported score of a player is better than the best score ever recorded for this player. If so, Huawei game server will update all involved leaderboards with the new score.

A game can have up to 70 leaderboards, and a leaderboard can have up to 5000 records.

Huawei game server automatically creates the daily, weekly, and all-time versions for a leaderboard. For example, the server can generate the daily, weekly, and all-time versions for a round-finishing time leaderboard of a racing game. You do not need to create a leaderboard for each time frame.

Leaderboards reset data based on the local time of the corresponding game server. For example, the China site adopts UTC+08:00. The daily leaderboard is reset at 00:00 every day, and the weekly leaderboard is reset at 24:00 on Saturday for the Europe site and at 24:00 on Sunday for other sites. A leaderboard displays only rankings of players from the same site.

If entries on your leaderboards are ranked by currency amount, you need to perform exchange rate conversion on your own. Huawei game server only ranks reported values without units.

How To Create A Leaderboard?

Leaderboards are created on the console. For this, firstly log-in Huawei AGC Console.

Select “My Apps” -> Your App Name -> “Operate” -> “Leaderboards”

In this page, you can see your leaderboards and you can create a new leaderboard by clicking “Create” button.

View attachment 5214011

After clicked “Create” button, you will see leaderboard detail page. In this page you should give some information for your leaderboard. So, an leaderboard should contain the following basic attributes:

Leaderboard ID: A unique string generated by AppGallery Connect to identify a leaderboard.

Leaderboard Name: Name of a leaderboard. How to name a leaderboard is up to you.

Score: Score of a player on a leaderboard. Scores can only be uploaded by Game Service APIs upon score changes, but cannot be directly defined during leaderboard creation.

Custom Unit: For a numeric leaderboard, you can customize a unit for numbers, for example, meter or kilometer.

Icon: Icon associated with a leaderboard. The icon must be of the resolution 512 x 512 px, and in PNG or JPG format. Avoid using any texts that need to be localized in the icon.

Ordering Mode: Ordering mode of leaderboard entries. You can define whether a larger or smaller score is better. Once a leaderboard is released, the mode cannot be modified.

Limits: Lower and upper limits of scores allowed by a leaderboard. The setting can help discard scores that are clearly fraudulent. Once a leaderboard is released, the limits cannot be modified.

List Order: Order of a leaderboard among all leaderboards. You need to set this attribute when creating a leaderboard.

Multi-Language: Multi-language information of a leaderboard. You can define what languages your game supports when creating a leaderboard. You need to define the leaderboard name and custom unit (if defined) in each supported language.

Score Format: You can define the score format as any of the following when creating a leaderboard:

Currency: Displays scores in a currency format. A score value represents a currency amount.

Time: Displays scores in a time format.

Numeric: Displays scores as numbers. You can customize a unit for them.

View attachment 5214013

After type all of the necessary information, click the “Save” button and save. After saving, you will be see again Leaderboards list. And you have to click “Release” button for start to using your leaderboard. Also, you can edit and see details of leaderboards in this page. But you must wait 1–2 days for the leaderboards to be approved. You can login the game with your developer account and test it until it is approved. But it must wait for approval before other users can view the leaderboards.

Displaying Scores

1. Create Score List (Leaderboard) Page

Firstly, create a Xml file, and add recyclerView to list all of the leaders. You can find my design in the below.

View attachment 5214015

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="70dp"
android:id="@+id/relativeLay">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Leadership"
android:textSize="25dp"
android:textAllCaps="false"
android:gravity="center"
android:textColor="#9A9A9B"
android:fontFamily="@font/muli_regular"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvFavorite"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="25dp"/>
</RelativeLayout>

Read full article.

Tips & Tricks

Remember that each leaderboard has a different ID. So, you must set the ID value of the leaderboard you want to use.

You can create diffirent leaderboards for diffirent game types.

Before calling archive APIs, ensure that the player has signed in.

Conclusion

Thanks to this article, you can create a Leaderboard on the console. Also, you can submit a score and list your leaders on your game app. Also, you can create a Saved Games, you can update and list your saved game details on your game app. You can see saved game detail logs on the below.

View attachment 5214039

References

HMS Game Service

Read full article.