Object undefined

Hello, I am writing a small text-based rpg. The issue I'm having is I instantiate a spell in the main function but in a different function in a different .cpp file that has the combat code it says the spell if undefined.

Here is the code snippets

First the spell header
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Spell.h
#ifndef SPELL_H
#define SPELL_H

#include <string>
#include "Range.h"

struct Spell
{
	std::string mName;
	Range mDamageRange;
	int mMagicPointsRequired;
};

#endif 


Then the beginning of the main function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int main()
{
	//Seed random number generator
	srand(time(0));

	//Instantiate a game map
	Map gameMap;

	//Instantiate the main player
	Player mainPlayer;

	//Go to create a class for main player
	mainPlayer.createClass();

	//Instantiate fireball spell
	Spell fireBall;

	fireBall.mName = "FireBall";
	fireBall.mDamageRange.mLow = 5;
	fireBall.mDamageRange.mHigh = 10;
	fireBall.mMagicPointsRequired = 10;


and lastly the combat code where I'm getting the error
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
	else if (mClassName == "Wizard")
	{
		int selection = 0;
		cout << "1)Attack 2)Run 3)Cast Spell : ";
		cin >> selection;
		cout << endl;

		switch (selection)
		{
		case 1:
			cout << "You attack an " << monster.getName() <<
				" with a " << mWeapon.mName << endl;

			if (Random(0, 20) < mAccuracy)
			{
				int damage = Random(mWeapon.mDamageRange);
				int totalDamage = damage - monster.getArmor();

				if (totalDamage <= 0)
					cout << "Your attack failed to penetrate the monster's armor!" << endl;

				else
				{
					cout << "You attack for " << totalDamage << " Damage!" << endl;

					//subtract from monsters hitpoints
					monster.takeDamage(totalDamage);
				}
			}

			else
				cout << "You miss!" << endl;

			cout << endl;
			break;

		case 2:
			//25% chance of running
			int roll = Random(1, 4);

			if (roll == 1)
			{
				cout << "You run away!" << endl;
				return true; //Return out of function
			}

			else
			{
				cout << "You could not escape!" << endl;
				break;
			}

		case 3://Cast Spell
			cout << "1)FireBall, 2)Black Spell of Destruction : ";
			int spellSelection = 0;
			cin >> spellSelection;

			//Check to see which spell the user chose
			if (spellSelection == 1)
			{
				//See if Player has enough Magic points
				if (mMagicPoints >= fireBall.mMagicPointsRequired)
				{

				}
			}
		}
	}


line 62 is where the error is.

Thanks.
How do you get fireball to this file? You can't use variable defined in main in another function, unless you pass it as an argument.

How do you get fireball to this file? You can't use variable defined in main in another function, unless you pass it as an argument.


Well, there's my problem.

Thanks.
Topic archived. No new replies allowed.