Last active
June 18, 2018 18:36
-
-
Save johnX9/56129e4ff6f82923da225cc4e6ba13cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@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; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You forgot updating the comment.