I tried the below code from a tutorial of a simple eos contract on a game but i get 10 errors while building it on eosstudio wasted a lot of time trying to figure the errors out but failed appreciate if anyone can help Thank you
#include <mygame.hpp>
#include <string>
using namespace eosio;
using std::string;
class mygame : public contract {
using contract::contract;
public:
// mygame( name self ) : contract(self){}
///@abi action
void add(const name account, string& username, uint64_t level){
require_auth(account);
playerIndex players(_self,_self);
// address_index addresses(_self, _self.value);
auto iterator = players.find(account);
eosio_assert(iterator == players.end(), "Address of account already exists")
players.emplace(account,[&] (auto& player){
player.account_name = account;
player.username = username;
player.level = 1;
player.health = 100;
player.points = 0;
});
}
///@abi action
void update(const name account, uint64_t level, uint64_t health, uint64_t points){
require_auth(account);
playerIndex players(_self,_self);
auto iterator = players.find(account);
eosio_assert(iterator != players.end(), "Address of account does not exists")
players.modify(iterator, account, [&] (auto& player){
player.level = level;
player.points += points;
if((player.health - health) < 0){
player.health = 0;
}else{
player.health -= health;
}
});
}
///@abi action
void getplayer(const name account){
playerIndex players(_self,_self.value);
auto iterator = player.find(account);
eosio_assert(iterator != players.end(), "Address of account does not exists")
auto currentPlayer = players.get(account);
print("username : ", currentPlayer.username.c_str(), "level : ", currentPlayer.level, "helth : ", currentPlayer.health, "points : ", currentPlayer.points);
}
private:
///@abi table player uint64
struct player {
uint64_t account_name;
string username;
uint64_t level = 1;
uint64_t health = 100;
uint64_t points = 0;
uint64_t primary_key() const {return account_name;}
EOSLIB_SERIALIZE(player, (account_name)(username)(level)(health)(points))
};
typedef multi_index<N(player), player> playerIndex;
}
EOSIO_DISPATCH(mygame, (add)(update)(getplayer))
below are the errors shown
/project/src/mygame.cpp:84:25: error: 'player' does not refer to a value
typedef multi_index<N(player), player> playerIndex;
^
/project/src/mygame.cpp:71:10: note: declared here
struct player {
^
/project/src/mygame.cpp:18:17: error: excess elements in scalar initializer
playerIndex players(_self,_self);
^ ~~~~~~
/project/src/mygame.cpp:37:17: error: excess elements in scalar initializer
playerIndex players(_self,_self);
^ ~~~~~~
/project/src/mygame.cpp:58:17: error: excess elements in scalar initializer
playerIndex players(_self,_self.value);
^ ~~~~~~~~~~~~
/project/src/mygame.cpp:59:21: error: 'player' does not refer to a value
auto iterator = player.find(account);
^
/project/src/mygame.cpp:71:10: note: declared here
struct player {
^
/project/src/mygame.cpp:63:26: error: use of undeclared identifier 'currentPlayer'
print("username : ", currentPlayer.username.c_str(), "level : ", currentPlayer.level, "helth : ", currentPlayer.health, "points : ", currentPlayer.points);
^
/project/src/mygame.cpp:63:70: error: use of undeclared identifier 'currentPlayer'
print("username : ", currentPlayer.username.c_str(), "level : ", currentPlayer.level, "helth : ", currentPlayer.health, "points : ", currentPlayer.points);
^
/project/src/mygame.cpp:63:103: error: use of undeclared identifier 'currentPlayer'
print("username : ", currentPlayer.username.c_str(), "level : ", currentPlayer.level, "helth : ", currentPlayer.health, "points : ", currentPlayer.points);
^
/project/src/mygame.cpp:63:138: error: use of undeclared identifier 'currentPlayer'
print("username : ", currentPlayer.username.c_str(), "level : ", currentPlayer.level, "helth : ", currentPlayer.health, "points : ", currentPlayer.points);
^
/project/src/mygame.cpp:88:1: error: expected unqualified-id
EOSIO_DISPATCH(mygame, (add)(update)(getplayer))
^
/usr/opt/eosio.cdt/1.6.1/bin/../include/eosiolib/dispatcher.hpp:115:8: note: expanded from macro 'EOSIO_DISPATCH'
extern "C" { \
^
10 errors generated.
Error while processing /project/src/mygame.cpp.
abigen error
Warning, empty ricardian clause file
Warning, empty ricardian clause file
This is the reference to the video tutorial
https://www.youtube.com/watch?v=cfbZfdGsGAE&list=PLL5pYVd8AWtSW4lHcWplRP6rTybxxj3yu&index=12