Skip to content

Instantly share code, notes, and snippets.

@johnX9
Last active June 18, 2018 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnX9/56129e4ff6f82923da225cc4e6ba13cc to your computer and use it in GitHub Desktop.
Save johnX9/56129e4ff6f82923da225cc4e6ba13cc to your computer and use it in GitHub Desktop.
//@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
Copy link

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