PC SDK provides API to integrate the Stove platform’s game support service into the game. The game support service supported by the PC SDK includes stats, achievements, and leaderboards. Each service is defined as follows:

To use the API for PC SDK game support service, you need to first conduct metadata registration for game support services through the studio.

For information on metadata management, refer to the Simple Console User Manual.

1. Callback Settings

To communicate with the PC SDK using the game support service API, you must define a class callback delegation method in the game to connect to the callback of the StovePCCallback class below.

public class StovePCCallback
{
    public StovePCErrorDelegate OnError;
    public StovePCInitializationCompleteDelegate OnInitializationComplete;
    public StovePCTokenDelegate OnToken;
    public StovePCUserDelegate OnUser;
    public StovePCOwnershipDelegate OnOwnership;

    // It calls the callback when you have completed GetStat.
    public StovePCStatDelegate OnStat;

    // It calls the callback when you have completed SetStat.
    public StovePCSetStatDelegate OnSetStat;

    // It calls the callback when you have completed GetAchievement.
    public StovePCAchievementDelegate OnAchievement;

    // It calls the callback when you have completed GetAllAchievement.
    public StovePCAllAchievementDelegate OnAllAchievement;

        // It calls the callback when you have completed GetRank.
    public StovePCRankDelegate OnRank;
}

Connect the callback delegation to the callback of the StovePCCallback class as in Integration 2) Config, Callback Settings.

// Create instance of the StovePCCallback class
this.callback = new StovePCCallback
{
    OnError = new StovePCErrorDelegate(this.OnError),
    OnInitializationComplete = new StovePCInitializationCompleteDelegate(this.OnInitializationComplete),
    OnToken = new StovePCTokenDelegate(this.OnToken),
    OnUser = new StovePCUserDelegate(this.OnUser),
    OnOwnership = new StovePCOwnershipDelegate(this.OnOwnership),

    // Game support service
    OnStat = new StovePCStatDelegate(this.OnStat),
    OnSetStat = new StovePCSetStatDelegate(this.OnSetStat),
    OnAchievement = new StovePCAchievementDelegate(this.OnAchievement),
    OnAllAchievement = new StovePCAllAchievementDelegate(this.OnAllAchievement),
    OnRank = new StovePCRankDelegate(this.OnRank)
};

You do not need to implement callbacks other than OnStatOnSetStatOnAchievementOnAllAchievement, and OnRank.

You only need to implement and connect the callback methods required for the game support service used by the game.

2. Update User Stats

Update specific stats in the game for a logged-in user with the StovePC.SetStat method.

// Input parameters
// string statId : Stat identifier registered in the studio
// int statValue : Stat value to be updated
StovePCResult result = StovePC.SetStat("STAT_ID", STAT_VALUE);
if(result == StovePCResult.NoError)
{
    // Processed as a success
}

When the StovePC.SetStat function is processed properly, the OnSetStat callback is called.

The StovePCStatValue structure delivered to the callback contains a flag indicating the current stat value, update status, and error messages.

Suppose it fully reflects and updates the stat value. In that case, the Updated field will contain ‘true’, and the ErrorMessage field will have an empty string. If the stat value is partially updated, the Updated field will contain ‘true’. The ErrorMessage field will contain a string such as “integer overflow”.

For example, you are assuming that the current stat value of the INCREMENT type is 2,147,483,000. You try to add 1,000 through the StovePC.SetStat API. It will become out of range of the values that the Int32 type can have. When it updates to 2,147,483,647, the maximum value of the Int32 type, reflecting only part of the value (1,000), the ErrorMessage field will contain a string such as “integer overflow”.