Issue with Quest System

quest.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <vector>
#include <string>
#include <quest.h>

using namespace std;

void init_questlog(){

	for (int x = 0; x < max_quests; x++){
	quest_log[x].title = "Empty";}

}

void add_questlog(string quest_title, string quest_objective, int quest_objective_number){

for (int x; x <= max_quests; x++){


}

}


quest.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <string>

using namespace std;

const int max_quests = 25;

struct quest{

string title;
string objective;
int objective_number;

}quest_log[max_quests];

void init_questlog();
void add_questlog(string item);


main.cpp

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
#include <player.h>
#include <inventory.h>
#include <quest.h>
#include <iostream>

using namespace player;

int main(){
	
	//Logic Phase
	init_inventory();
	init_questlog();
	
	for (int x = 0; x < 25; x++)
	{
	
	cout << x << ":" << quest_log[x].title;
	
	}
	
	//Initial Graphics Phase
		//Open render window
		//Load Graphics
		
	//Game loop
	
	//Render phase
	
return 0;
}

I'm still getting my bearings when it comes to object oriented programming, I'm really learning as I go, but I am getting a message that doesn't make sense to me when I try and compile this code.

quest.cpp:(.bss+0x0): multiple definition of `quest_log'
main.cpp:(.bss+0x0): first defined here
[Error] ld returned 1 exit status

Last edited on
}quest_log[max_quests];

This object is defined in a header file and is then included in multiple files, you can't do this. Also, it's a global variable, and you should not have global variables.

quest_log should be in main and should be its own class, init_questlog and add_questlog should be members of the class.
That makes a lot more sense, and yeah I've heard the global variable thing, but I was also reading that in games it's sometimes necessary. Thank you very much :).
Topic archived. No new replies allowed.