C++ Videogame Problems >.

0 Cristiano Cappagli · October 17, 2015
Hi guys, i'm practicing in creating c++ videogames, in this code i'd like to test a fight and in particular the increase of the EXP and GOLD of the player. i created a player class and an enemy class( i know they should be in a different file but don't mind about that). so at the beginning of the main i set player and enemy stats, and when i use the fight() function i need to use 5 paramethers. the first 3 are just a copy because i don't need a permanent change, instead i want a change in the exp and gold of the player... until it was just


fight(rat.getHP(), rat.getEXP(), rat.getGOLD())

it worked as i wanted, but when i added the third and forth:


fight(rat.getHP(), rat.getEXP(), rat.getGOLD(), &player.getEXP(), &player.getGOLD());

i've got an error saying: lvalue required as unary '&' operand. what's the meaning? This is the main:

class Player{
public:
    void setGOLD(int x){
        GOLD = x;
    }
    int getGOLD(){
        return GOLD;
    }

    void setEXP(int x){
        EXP = x;
    }
    int getEXP(){
        return EXP;
    }

private:
    int GOLD;
    int EXP;
};



class Enemy{
public:
    //SET HP
    void setHP(int x){
        HP = x;
    }
    int getHP(){
        return HP;
    }
    //SET GOLD
    void setGOLD(int x){
        GOLD = x;
    }
    int getGOLD(){
        return GOLD;
    }
    //SET EXP
    void setEXP(int x){
        EXP = x;
    }
    int getEXP(){
        return EXP;
    }
private:
    int HP;
    int GOLD;
    int EXP;
};


I cant insert properly the main and fight function so i'll upload 2 images:/images/forum/upload/2015-10-17/36c25f5aca4ad5df7adde747dd149ef0.JPG/images/forum/upload/2015-10-17/c2cf760fe88e33e8e5e6769f4a1948e2.JPG 

Dont mind about the dumb combat system LOL
Uhm i hope i explained the problem right :)
Structures suggestions are welcome :D
i'm just a newbie lol.
Thanks everyone ;) 

Post a Reply

Replies

Oldest  Newest  Rating
0 c student · October 18, 2015
how many values can you return in a function?
0 Scott Walker · October 18, 2015
What is the actual error message?
Also could you copy the whole code in one please? Makes it easier to take into development :-)
0 Cristiano Cappagli · October 19, 2015
Uhm why remove setters and getters? i think i need them since variables in class are private... :P
0 Cristiano Cappagli · October 19, 2015
you can see the error in the first image, and yea i wanted to write the code in one, but the website kinda bugged it so i decided to take 2 screenshots :P if you can't work with it i'll try to upload it all in one code ;)
0 Cristiano Cappagli · October 21, 2015
well i would, i didn't do that because usually they are stored as private... anyway i'll try using them as public that'll certainly work i guess :P
  • 1

C++

107,032 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator