Stats #

Read more about the Stats system in Hiro here.

Get all stats #

Get all stats.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
void onStatsGet(const Hiro::StatList& statList)
{
    for (auto it = statList.public_.begin(); it != statList.public_.end(); it++)
    {
        std::cout << "Found public stat: " << it->second.name << '\n';
    }

    for (auto it = statList.private_.begin(); it != statList.private_.end(); it++)
    {
        std::cout << "Found private stat: " << it->second.name << '\n';
    }
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

hiroClient->statsGet(session, onStatsGet, onError);

Update stats for the player #

Update stats.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void onStatsUpdate(const Hiro::StatList& statList)
{
    for (auto it = statList.public_.begin(); it != statList.public_.end(); it++)
    {
        std::cout << "Found public stat: " << it->second.name << '\n';
    }

    for (auto it = statList.private_.begin(); it != statList.private_.end(); it++)
    {
        std::cout << "Found private stat: " << it->second.name << '\n';
    }
}

void onError(const Nakama::NError& error)
{
    std::cout << Nakama::toString(error.code) << ": " << error.message << '\n';
}

Hiro::StatUpdateRequest request;

Hiro::StatUpdate statUpdate1;
statUpdate1.name = "public_stat_1";
statUpdate1.value = "100";
statUpdate1.operator_ = Hiro::StatUpdateOperator::STAT_UPDATE_OPERATOR_SET;
request.public_.push_back(statUpdate1);

Hiro::StatUpdate statUpdate2;
statUpdate2.name = "private_stat_1";
statUpdate2.value = "100";
statUpdate2.operator_ = Hiro::StatUpdateOperator::STAT_UPDATE_OPERATOR_SET;
request.private_.push_back(statUpdate2);

hiroClient->statsUpdate(session, request, onStatsUpdate, onError);