Energy #

Read more about the Energy system in Hiro here.

Get all energies #

Get the energies and their current timers for the player.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
void onEnergyGet(const Hiro::EnergyList& energyList)
{
    for (auto it = energyList.energies.begin(); it != energyList.energies.end(); it++)
    {
        std::cout << "Found energy: " << it->first << " with value: " << it->second.current << '\n';
    }
}

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

hiroClient->energyGet(session, onEnergyGet, onError);

Spend one or more energies #

Spend one or more energies for the player.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
void onEnergySpend(const Hiro::EnergySpendReward& energySpendReward)
{
    for (auto it = energySpendReward.energies.energies.begin(); it != energySpendReward.energies.energies.end(); it++)
    {
        std::cout << "Found energy: " << it->first << " with value: " << it->second.current << '\n';
    }
}

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

Hiro::EnergySpendRequest request;
request.amounts.insert(std::make_pair<std::string, int32_t>("power", 10));
request.amounts.insert(std::make_pair<std::string, int32_t>("tickets", 1));

hiroClient->energySpend(session, request, onEnergySpend, onError);

Granting energy #

While energy can be granted as part of a reward, you can also grant it directly.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
void onEnergyGrant(const Hiro::EnergyList& energyList)
{
    for (auto it = energyList.energies.begin(); it != energyList.energies.end(); it++)
    {
        std::cout << "Found energy: " << it->first << " with value: " << it->second.current << '\n';
    }
}

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

Hiro::EnergyGrantRequest request;
request.amounts.insert(std::make_pair<std::string, int32_t>("power", 10));
request.amounts.insert(std::make_pair<std::string, int32_t>("tickets", 1));

hiroClient->energyGrant(session, request, onEnergyGrant, onError);