6 Replies - 186 Views - Last Post: 03 October 2012 - 09:45 AM Rate Topic: -----

#1 bean_grinder  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 8
  • Joined: 02-October 12

Ye Olde noob game struct func error

Posted 03 October 2012 - 07:03 AM

Making progress and need help with this error. Also could someone show me the correct way to keep track of the players xy coord. Thanks.

Two Errors when i try to compile =
LNK2001: unresolved external symbol "struct s_World * w_areas" (?w_areas@@3PAUs_World@@A)
LNK1120: 1 unresolved externals

Here's the code I have so far:

#include "stdafx.h"
#include <iostream>
#include "windows.h"

using namespace std;


///////////////////////////////////////////////////////////////////////////

struct s_World
{
	int m_world_area;
	int m_world_boundary;
};
struct s_Area
{
	int m_area_room;
	int m_area_other;
	int m_area_boundary;
};
struct s_Room
{
	int m_room_xyCoord;
	int m_room_object;
	int m_room_box;
};
struct s_Box
{
	int m_box_desription;
	int m_box_puzzle;
};
struct s_Puzzle
{
	int m_puzzle_description;
	int m_puzzle_clue;
	int m_puzzle_collectable;
};

struct s_Player
{
	int m_player_backpack;
	int m_player_notebook;
	int m_player_location;
	int m_player_number;
};

//////////////////////////////////////////////////////////////////////////
s_World w_areas [];
s_World w_boundaries[];

s_Area a_rooms[];
s_Area a_others[];
s_Area a_boundaries[];

s_Room r_contents [] =
{
	{10, -1, -1,},
	{20, 1, -1,},
	{30, 1, 1,},
	{40, -1, 1,}
};

s_Box bx_descriptions[];
s_Box bx_puzzles[];

s_Puzzle puz_descriptions[];
s_Puzzle puz_clues[];
s_Puzzle puz_collectables[];

s_Player bpk_inventories[];
s_Player nbk_inventories[];
s_Player plr_number[];
s_Player plr_location[];
s_Player plr_turns[];

//////////////////////////////////////////////////////////////////////////////

int main()
{
	for(int i=0; i<100; i++)
	{
		cout << w_areas[i].m_world_area << ' ' ;
		if (w_areas[i].m_world_area <= 25)
			cout << "You are in Upper World.\n";
		else if (26 <= w_areas[i].m_world_area <= 50)
			cout << "You are in Northern World .\n";
		else if (51 <= w_areas[i].m_world_area <= 75)
			cout << "You are in Southern World.\n";
		else if (76 <= w_areas[i].m_world_area <=100)
			cout << "You are in lower World.\n";
		else cout<< "You are lost.\n";
	}
	

	for (int i=0; i<4; i++)
	{
		cout << r_contents[i].m_room_xyCoord << ' '
			 << r_contents[i].m_room_object << ' '
			 << r_contents[i].m_room_box << endl;

		if (r_contents[i].m_room_xyCoord == 10)
			cout << "You are in the kitchen.\n";
		else if (r_contents[i].m_room_xyCoord == 20)
			cout << "You are in the basement.\n";
		else if (r_contents[i].m_room_xyCoord == 30)
			cout << "You are in the living room.\n";
		else if(r_contents[i].m_room_xyCoord == 40)
			cout << "You are in the bathroom.\n";
		else if(r_contents[i].m_room_xyCoord == 50)
			cout << "You are in the garage.\n";
		else
			cout  << "Neither you or I know where you are.\n";
		
		
		if (r_contents[i].m_room_object == 1)
			{
			cout << "There is an object in the corner.\n";
			}
		if (r_contents[i].m_room_box == 1)
			{
			cout << "There is a box in the corner.\n";
			}
	}
	system("pause");
	return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Ye Olde noob game struct func error

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 3989
  • View blog
  • Posts: 12,305
  • Joined: 25-December 09

Re: Ye Olde noob game struct func error

Posted 03 October 2012 - 07:19 AM

A couple of things, first you should stop using all the global variables. These global variables will make your program hard to maintain because any function can change these variables at any time. So as your program grows it becomes harder and harder to remember where and when these variables change. Learn to pass variables to and from your functions. And since at this point you don't have any functions now is the time to put these variables into your only function (main()).

Next look at the following snippet:
s_World w_areas [];
s_World w_boundaries[];

s_Area a_rooms[];
s_Area a_others[];
s_Area a_boundaries[];



You can't have zero sized arrays in C/C++, you need to provide a size. Your compiler should be warning you about this issue. And if you are getting warnings or errors please post these warnings when you post your code. And never ignore warnings, always fix them. Most warnings are telling you that while the program is "correct" it probably won't produce the output you desire.

Lastly I don't recommend including windows.h unless you are actually developing a Windows application. This header file includes quite a few other header files that are not usually required for console based applications. Also you should be including the <cstdlib> header file for the use of system().

Jim
Was This Post Helpful? 0
  • +
  • -

#3 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: Ye Olde noob game struct func error

Posted 03 October 2012 - 07:36 AM

It would be better if you review the logic of your code....

Also there exists no World, how are you gonna tell the player where he/she is?
Was This Post Helpful? 0
  • +
  • -

#4 bean_grinder  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 8
  • Joined: 02-October 12

Re: Ye Olde noob game struct func error

Posted 03 October 2012 - 07:36 AM

Thanks jimblumberg.

Addressing those issues now.
Was This Post Helpful? 0
  • +
  • -

#5 bean_grinder  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 8
  • Joined: 02-October 12

Re: Ye Olde noob game struct func error

Posted 03 October 2012 - 08:24 AM

AKMafia001,

When I create a World array:

World [10][10];


and try to fill each block inside with an area array that is also a 10 x 10:

area1 [10][10];
area2 [10][10];
area3 [10][10];

World [10][10] = 
{ {area1, area2, area3...and so forth


or like this:


int Area [10][10];
int World [10][10];


Wouldn't I have to point each Area "Area [0][0],[0][1],[0][2]+...+[10][10]" to each World " in like manner"?

There has got to be a better way...all without using classes.


I know this is not right since the errors.
And so I tried to use structs, and that seemed to at least temporarily solve my issue. But I do see a problem with the logic. I don't understand why everyone else in class sees this as simple, I cannot wrap my head around it. I just want to put the rooms inside the areas inside the world.
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is online

  • member icon


Reputation: 3989
  • View blog
  • Posts: 12,305
  • Joined: 25-December 09

Re: Ye Olde noob game struct func error

Posted 03 October 2012 - 09:30 AM

You may want to study the following links: Arrays, Character sequences.

Quote

When I create a World array:

World [10][10];


The above does not create an array in C++, you need to provide the type:
int world[10[10];
double myWorld[10];
char myChar[10];


You can also initialize an array when you create it like:
int world[3][3] = {{1,2,4},{90,100,3},{2,4,5}};



Jim
Was This Post Helpful? 0
  • +
  • -

#7 bean_grinder  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 8
  • Joined: 02-October 12

Re: Ye Olde noob game struct func error

Posted 03 October 2012 - 09:45 AM

Yes. Forgot to post the type, and I know how to initialize one. Reading. Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1