Skip to content

Instantly share code, notes, and snippets.

@johnX9

johnX9/Players.cpp

Last active Jun 18, 2018
Embed
What would you like to do?
//@abi action
void update(account_name account, uint64_t level, int64_t healthPoints, int64_t energyPoints) {
require_auth(account);
playerIndex players(_self, _self);
auto iterator = players.find(account);
eosio_assert(iterator != players.end(), "Address for account not found");
/**
* We add the new player in the table
* The first argument is the payer of the storage which will store the data
*/
players.modify(iterator, account, [&](auto& player) {
player.level = level;
if ((player.health_points - healthPoints) < 0) {
player.health_points = 0;
} else {
player.health_points -= healthPoints;
}
if ((player.energy_points - energyPoints) < 0) {
player.energy_points = 0;
} else {
player.energy_points -= energyPoints;
}
});
}
@Falci

This comment has been minimized.

Copy link

@Falci Falci commented Jun 18, 2018

You forgot updating the comment.

/**
 * Find and update the player in the table
 * The first argument is the current player, the second is the payer of the storage which will store the data
 */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.