Skip to content

Instantly share code, notes, and snippets.

@johnX9

johnX9/Players.cpp

Last active Apr 29, 2018
Embed
What would you like to do?
//@abi action
void add(const account_name account, string& username) {
/**
* We require that only the owner of an account can use this action
* or somebody with the account authorization
*/
require_auth(account);
/**
* We access the "player" table as creating an object of type "playerIndex"
* As parameters we pass code & scope - _self from the parent contract
*/
playerIndex players(_self, _self);
/**
* We must verify that the account doesn't exist yet
* If the account is not found the iterator variable should be players.end()
*/
auto iterator = players.find(account);
eosio_assert(iterator == players.end(), "Address for account already exists");
/**
* We add the new player in the table
* The first argument is the payer of the storage which will store the data
*/
players.emplace(account, [&](auto& player) {
player.account_name = account;
player.username = username;
player.level = 1;
player.health_points = 1000;
player.energy_points = 1000;
});
}
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.