Need help retrieving data from moves.

my current program runs but does not work properly, rather than retrieving the values in each move itself, it instead retrieves its location, i'm just trying to fix this error retrieving data from moves

Because this program is rather large (and split across 7 files to improve readability), i put them in a .zip file and posted them to a temporary facebook group, so it'd be easier to help fix this problem... if you run the code and say 'pick move 1' it will produce an outragious number in the millions.

temp group to where it is posted
Last edited on
Any help would be much appreciated, in trying to resolve this issue.
Instead of asking us to go through 7 files of code, could you post bits that you believe you have a problem with? It's difficult to find someone who's willing to download your code and take hours out of their day figuring out what every bit of it means in order to discover the problem you're having; seeing as your description was pretty vague too.
Facebook wrote:
You must log in to see this page.
sigh
is that a chess code. I am also writing one...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
void BattlePhase (Monster & monster1, Monster & monster2)//does the battle phase
{	string Category;
	int SpAtk;
	int SpDef;
	Moves move;
	double CriticalHit;
	double STAB = 1.5;//Same Type Attack Bonus Default (to be changed and location moved)
	int Range;
	int Damage;
	double Type1 = 1;

    while (monster1.GetHealth() > 0 && monster2.GetHealth() > 0)
    {	if(monster1.GetHealth() > 0)
        {	move = monster1.AskMove();
	        if (move.GetCategory() == "Physical")
            {	SpAtk = monster1.GetAttack();
				SpDef = monster2.GetDefense();
			}
            else
            {	SpAtk = monster1.GetSpAttack();
                SpDef = monster2.GetSpDefense();
			}
            CriticalHit = rand() % 16 + 1;
            if (CriticalHit == 8)
				{CriticalHit = 1.5;}
            else
				{CriticalHit = 1;}
            Range = rand() % 15 + 85;
			Type1 = Monster::CompareYourTurn(monster1, monster2);
			Damage =(((((((monster1.GetLevel() * 2 / 5) + 2) * move.GetPower() * SpAtk / 50) / SpDef) + 2) * CriticalHit * Range / 100) * STAB * Type1);
			cout << "You attacked and dealt " << Damage <<" Damage\n";
			monster2.SetHealth(monster2.GetHealth() - Damage); 
			cout << "Your opponents health is " << monster2.GetHealth() << "\n\n";
			if(monster2.GetHealth() <= 0) 
			{	cout <<"You Win!"<< "\n\n";
			}
			cin.ignore(numeric_limits<streamsize>::max(), '\n');
		}
		if (monster2.GetHealth() > 0)
		{	move = monster2.RandMove();
            if (Category == "Physical")
            {	SpAtk = monster2.GetAttack();
                SpDef = monster1.GetDefense();
			}
            else
            {	SpAtk = monster2.GetSpAttack();
                SpDef = monster1.GetSpDefense();
			}
            CriticalHit = rand() % 16 + 1;
            if (CriticalHit == 8)
				{CriticalHit = 1.5;}
            else
				{CriticalHit = 1;}
            Range = rand() % 15 + 85;
			Type1 = Monster::CompareOpponentTurn (monster1, monster2);
			Damage =(((((((monster2.GetLevel() * 2 / 5) + 2) * move.GetPower() * SpAtk / 50) / SpDef) + 2) * CriticalHit * Range / 100) * STAB * Type1);
			cout << "Your opponent attacked and dealt " << Damage <<" Damage\n";
			monster1.SetHealth(monster1.GetHealth() - Damage); 
			cout << "Your health is " << monster1.GetHealth() << "\n\n";   
			if(monster1.GetHealth() <= 0) 
			{	cout <<"You Lose :(\n\n";
			}
			cin.ignore(numeric_limits<streamsize>::max(), '\n');
		} 
     }            
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Moves & Monster::AskMove ()
{	int INPUT;

	do
	{	cout << "Which move would you like to do (1-4)?\n";
	    cin >> INPUT;
	    switch (INPUT)
		{	case 1: move = move1; 
					break;
                            
            case 2: move = move2; 
					break; 
                            
            case 3: move = move3; 
					break;
                            
	        case 4:	move = move4;       
					break;                        

	        default: cout << "Invalid Choice, ";
        }
	} while (INPUT != 1 && INPUT != 2 && INPUT != 3 && INPUT != 4);
	return move;
}

Moves & Monster::RandMove ()
{	int INPUT;

	do
	{	cout << "Opponent Picks";
		INPUT = rand() % 4 + 1;
		switch (INPUT)
		{	case 1: move = move1;
		    		break;
                            
            case 2: move = move2; 
					break; 
                            
            case 3: move = move3; 
					break;
                            
	        case 4:	move = move4;       
					break;                        

	        default: cout << "Invalid Choice, ";
        }
	} while (INPUT != 1 && INPUT != 2 && INPUT != 3 && INPUT != 4);    
	return move;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
Moves Move1 ("Normal", "Physical", 20, 100, 10); 
Moves Move2 ("Normal", "Physical", 30, 100, 10);
Moves Move3 ("Normal", "Physical", 40, 100, 10);
Moves Move4 ("Normal", "Physical", 50, 100, 10);

Monster::Monster()
{}

Monster::~Monster()
{}    

void Monster::Display()
{	cout << "--------Monster Stats--------------------";
    cout << "\nType:" << Type;
    cout << " Name:" << MonsterName;
    cout << "\nAdvantage:" << Advantage;
    cout << " Disadvantage:" << Disadvantage;
    cout << "\nAtk:----------> " << Atk;
    cout << "\nDef:----------> " << Def;
    cout << "\nSpAtk---------> " << SpAtk;
    cout << "\nSpDef---------> " << SpDef;
    cout << "\nHP:-----------> " << HP;
    cout << "\nSpeed:--------> " << Speed;
    cout << "\nLevel:--------> " << Level;
    cout << "\nExperience:---> " << Experience;
    cout << "\n-----------------------------------------\n";
} 
string Monster::GetType() 
{ return Type; }

void Monster::SetType(string x) 
{ Type = x; }
      
int Monster::GetAttack() 
{ return Atk; 
}

void Monster::SetAttack(int x) 
{ Atk = x; }
           
int Monster::GetDefense() 
{ return Def; }

void Monster::SetDefense(int x) 
{ Def = x; }
      
int Monster::GetSpAttack() 
{ return SpAtk; }

void Monster::SetSpAttack(int x) 
{ SpAtk = x; }
           
int Monster::GetSpDefense() 
{ return SpDef; }

void Monster::SetSpDefense(int x) 
{ SpDef = x; }
      
int Monster::GetHealth() 
{ return HP; }

void Monster::SetHealth(int x) 
{ HP = x; }

      
int Monster::GetSpeed() 
{ return Speed; }

void Monster::SetSpeed(int x) 
{ Speed = x; }
      
string Monster::GetAdvantage() 
{ return Advantage; }

void Monster::SetAdvantage(string x) 
{ Advantage = x; }

string Monster::GetDisadvantage() 
{ return Disadvantage; }

void Monster::SetDisadvantage(string x) 
{ Disadvantage = x; }
      
string Monster::GetMonsterName() 
{ return MonsterName; }

void Monster::SetMonsterName(string x) 
{ MonsterName = x; }
      
int Monster::GetLevel() 
{ return Level; }

void Monster::SetLevel(int x) 
{ Level = x; }
      
int Monster::GetExperience() 
{ return Experience; }

void Monster::SetExperience(int x) 
{ Experience = x; }

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class Monster // Defines the existance of monsters
{	string Type;
    int Atk;
    int Def;
    int HP;
    int SpAtk;
    int SpDef;
    string Advantage;
    string Disadvantage;
    string MonsterName;
    int Speed;
    int Level;
    int Experience;
    Moves move;
	Moves move1;
	Moves move2;
	Moves move3;
	Moves move4;

public: 
	Monster();
	~Monster();

    void Display();

    string GetType();
    void SetType(string x);
      
    int GetAttack();
    void SetAttack(int x);
           
    int GetDefense();
    void SetDefense(int x);
      
    int GetSpAttack();
    void SetSpAttack(int x);
           
    int GetSpDefense();
    void SetSpDefense(int x);
      
    int GetHealth(); 
    void SetHealth(int x);
      
    int GetSpeed();
    void SetSpeed(int x);
      
    string GetAdvantage();
    void SetAdvantage(string x);
      
    string GetDisadvantage();
    void SetDisadvantage(string x);
      
    string GetMonsterName();
    void SetMonsterName(string x);
      
    int GetLevel();
    void SetLevel(int x);

    int GetExperience();
    void SetExperience(int x);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Moves::Moves()
{}
Moves::Moves (string t, string cat, int p, int acc, int pp) 
{	Type = t; 
 	Category = cat; 
 	Power = p; 
 	Accuracy = acc; 
 	PP = pp; 
} 

Moves::~Moves ()
{}

string Moves::GetType() 
{ return Type; }

void Moves::SetType(string x) 
{ Type = x; }

string Moves::GetCategory() 
{ return Category; }

void Moves::SetCategory(string x) 
{ Category = x; }

int Moves::GetPower() 
{ return Power; }

void Moves::SetPower(int x) 
{ Power = x; }

int Moves::GetAccuracy() 
{ return Accuracy; }

void Moves::SetAccuracy(int x) 
{ Accuracy = x; }

int Moves::GetPP() 
{ return PP; }

void Moves::SetPP(int x) 
{ PP = x; }

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Moves
{	string Type;
	string Category;
	int Power;
	int Accuracy;
	int PP;

public:
Moves();
Moves::Moves (string t, string cat, int p, int acc, int pp); 
	~Moves();

	string GetType();
	void SetType(string x);

	string GetCategory();
	void SetCategory(string x);

	int GetPower(); 
	void SetPower(int x);

	int GetAccuracy();
	void SetAccuracy(int x);

	int GetPP();
	void SetPP(int x);

};
to the above post problem lies in battlephase function, (first part), and getting the data stored inside move1,move2,move3,move4 (third part), the compiler gets moves location rather than the values inside of it, thats the problem

the above posts are stuff where the moves are referenced/used, or defines stuff about the moves
Last edited on
Very short functions :
string Monster::GetType()
{ return Type; }

void Monster::SetType(string x)
{ Type = x; }

int Monster::GetAttack()
{ return Atk;
}

void Monster::SetAttack(int x)
{ Atk = x; }

int Monster::GetDefense()
{ return Def; }

void Monster::SetDefense(int x)
{ Def = x; }

int Monster::GetSpAttack()
{ return SpAtk; }

void Monster::SetSpAttack(int x)
{ SpAtk = x; }

int Monster::GetSpDefense()
{ return SpDef; }

void Monster::SetSpDefense(int x)
{ SpDef = x; }

int Monster::GetHealth()
{ return HP; }

void Monster::SetHealth(int x)
{ HP = x; }


int Monster::GetSpeed()
{ return Speed; }

void Monster::SetSpeed(int x)
{ Speed = x; }

string Monster::GetAdvantage()
{ return Advantage; }

void Monster::SetAdvantage(string x)
{ Advantage = x; }

string Monster::GetDisadvantage()
{ return Disadvantage; }

void Monster::SetDisadvantage(string x)
{ Disadvantage = x; }

string Monster::GetMonsterName()
{ return MonsterName; }

void Monster::SetMonsterName(string x)
{ MonsterName = x; }

int Monster::GetLevel()
{ return Level; }

void Monster::SetLevel(int x)
{ Level = x; }

int Monster::GetExperience()
{ return Experience; }

void Monster::SetExperience(int x)
{ Experience = x; }


Could be changed to :
string Monster::GetType() { return Type; }

void Monster::SetType(string x) { Type = x; }
      
int Monster::GetAttack() { return Atk; }

void Monster::SetAttack(int x) { Atk = x; }
           
int Monster::GetDefense() { return Def; }

void Monster::SetDefense(int x) { Def = x; }
      
int Monster::GetSpAttack() { return SpAtk; }

void Monster::SetSpAttack(int x) { SpAtk = x; }
           
int Monster::GetSpDefense() { return SpDef; }

void Monster::SetSpDefense(int x) { SpDef = x; }
      
int Monster::GetHealth() { return HP; }

void Monster::SetHealth(int x) { HP = x; }

      
int Monster::GetSpeed() { return Speed; }

void Monster::SetSpeed(int x) { Speed = x; }
      
string Monster::GetAdvantage() { return Advantage; }

void Monster::SetAdvantage(string x) { Advantage = x; }

string Monster::GetDisadvantage() { return Disadvantage; }

void Monster::SetDisadvantage(string x) { Disadvantage = x; }
      
string Monster::GetMonsterName() { return MonsterName; }

void Monster::SetMonsterName(string x) { MonsterName = x; }
      
int Monster::GetLevel() { return Level; }

void Monster::SetLevel(int x) { Level = x; }
      
int Monster::GetExperience() { return Experience; }

void Monster::SetExperience(int x) { Experience = x; }


Easier to read, right????

Moves move;
Moves move1;
Moves move2;
Moves move3;
Moves move4;


The similar definition :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Moves move[5];[/quote]
Easier to read, right????

Example :

[quote]Moves & Monster::AskMove ()
{	int INPUT;

	do
	{	cout << "Which move would you like to do (1-4)?\n";
	    cin >> INPUT;
	    switch (INPUT)
		{	case 1: move = move1; 
					break;
                            
            case 2: move = move2; 
					break; 
                            
            case 3: move = move3; 
					break;
                            
	        case 4:	move = move4;       
					break;                        

	        default: cout << "Invalid Choice, ";
        }
	} while (INPUT != 1 && INPUT != 2 && INPUT != 3 && INPUT != 4);
	return move;
}

Moves & Monster::RandMove ()
{	int INPUT;

	do
	{	cout << "Opponent Picks";
		INPUT = rand() % 4 + 1;
		switch (INPUT)
		{	case 1: move = move1;
		    		break;
                            
            case 2: move = move2; 
					break; 
                            
            case 3: move = move3; 
					break;
                            
	        case 4:	move = move4;       
					break;                        

	        default: cout << "Invalid Choice, ";
        }
	} while (INPUT != 1 && INPUT != 2 && INPUT != 3 && INPUT != 4);    
	return move;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Moves & Monster::AskMove ()
{	int INPUT = 0;

	do
	{	cout << "Which move would you like to do (1-4)?\n";
	    cin >> INPUT;

               if (INPUT >= 1 && INPUT <=  4)
                      move[0] = move[INPUT]; 
	} while  (INPUT >= 1 && INPUT <=  4);
	
return move[0];
}

Moves & Monster::RandMove ()
{	int INPUT = 0;

	cout << "Opponent Picks";

		INPUT = rand() % 4 + 1;
		if(INPUT >= 1 && INPUT <=  4)
		move[0] = move[INPUT];
		else cout << "Invalid Choice, ";

	return move[0];
}


Easier to read, right????
Last edited on
Easier
1
2
3
4
5
6
7
8
9
class Monster // Defines the existance of monsters
{
public: //useless getters and setters.
    string Type;
    int Atk;
    int Def;
    int HP;
//etc
};


About your issue,
¿where do you use the global Move{1..5} ?
¿where do you give a value to the members move{1..5} ?


@Jackson Marie: please fix your indentation.
Last edited on
1
2
3
4
5
6
7
public: //useless getters and setters.
    string Type;
    int Atk;
    int Def;
    int HP;
//etc
};


this part is not useless because, not posted but i have

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
void Monster::FireType () //The Fire Type
{	Type = "Fire";
	Advantage = "Nature";
	Disadvantage = "Water";
	MonsterName = "FireType";
	Atk = 6;
	Def = 1;
	SpAtk = 6;
	SpDef = 1;
	HP = 40;
	Speed = 10;
	Level = 5;
	Experience = 1000;
}

void Monster::WaterType () //The Water Type
{	Type = "Water";
	Advantage = "Fire";
	Disadvantage = "Nature";
	MonsterName = "WaterType";
	Atk = 6;
	Def = 1;
	SpAtk = 6;
	SpDef = 1;
	HP = 40;
	Speed = 10;
	Level = 5;
	Experience = 1000;
}

void Monster::NatureType () //The Nature Type
{	Type = "Nature";
	Advantage = "Water";
	Disadvantage = "Fire";
	MonsterName = "NatureType";
	Atk = 6;
	Def = 1;
	SpAtk = 6;
	SpDef = 1;
	HP = 40;
	Speed = 10;
	Level = 5;
	Experience = 1000;
}


as for my issue, i use my global move mainly in battlephase ()

lines 5,14-16,30,56 in battlephase function is where the use the data(part 1), and in line 1-4 (part 3) is where i give values to them (in post 6 on this page)
Last edited on
You didn't use the setters, ¿what's your point?
You are giving the same encapsulation as putting the members as public, but losing time and effort in writing all that crap.


lines 5,14-16,30,56 in battlephase function is where the use the data(part 1), and in line 1-4 (part 3) is where i give values to them (in post 6 on this page)
Nope, you give data to the globals but never use them
You use the members, that were not initialized.
C++ is case sensitive
Nope, you give data to the globals but never use them


that is the problem i am trying to solve, can you please help me fix that, as that was the whole reason why i created the thread in the first place
Last edited on
that is the problem i am trying to solve, can you please help me fix that, as that was the whole reason why i created the thread in the first place


You're not reading what he's telling you. You have defined and initialised global variables called Move1, Move2 etc, but you do not use them anywhere in your code. Instead, you are using the data members Monster::move1, Monster::move2 etc, which you have not initialised.
Last edited on
ill see if i can find a way to fix that, any help would be great, because i want each monster too have 4 moves and im aparently not using the global moves i created, which im trying to do
Last edited on
You're not using them because, well, you're not using them. You initialise them at the top of the 3rd code block you posted, and absolutely nothing anywhere else in your code makes any references to them whatsoever. The name Move1 appears nowhere in your posted code, apart from where it is initialised.

You are, however, using the data member move1, which you do not initialise anywhere.

To re-iterate something ne555 said - C++ is case-sensitive. That means that Move1 and move1 are considered to be different names.
Last edited on
Topic archived. No new replies allowed.