Home Town 2

Posted by Alkarindil on Sat 09 Jun 2007 02:53 AM — 13 posts, 42,442 views.

Brazil #0
Hej!
I am making a town's option to my mud.
So, we have a "../hometowns/" folder, a "town.lst" file and the towns files.
I just used the same lines we use to the races.
So, I can make some races illegal to some towns.
I've made an option on the register of a new character, etc.
But I get 5 errors that I don't know where to fix.
Can anybody help-me in this please?
It's almost the same code of races, but with another variable names, etc.. If we replace the "race"s with "town"s, that's almost what I have here.
The compiler returns me this:
----------------------
Compiling...
tables.c
Linking...
comm.obj : error LNK2001: unresolved external symbol _town_table
tables.obj : error LNK2001: unresolved external symbol _town_table
comm.obj : error LNK2001: unresolved external symbol _MAX_PC_TOWN
tables.obj : error LNK2001: unresolved external symbol _MAX_PC_TOWN
smaug.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

smaug.exe - 5 error(s), 0 warning(s)
----------------------
Australia Forum Administrator #1
What file is town_table in? It sounds like, whatever that file is, you haven't added it to the list of files to be linked in the Makefile.
Brazil #2
It must be a race_table copy. Where is race_table?
hard life...
Australia Forum Administrator #3
Have you read:

http://www.gammon.com.au/smaug/howtocompile.htm

That has information about finding stuff in files, amongst other things.
Brazil #4
Ok.. I saw the page. And I downloaded some linux here, I will try to transfer everything to the other system.. =D
But I still with the same error. I asked some friends for some help, but nothing...

Do u have another tip?
thanks!
Australia Forum Administrator #5
You have an undefined symbol town_table, according to the error message.

You need to work out what file that is in, and make sure it is linked as part of the linking phase.
USA #6
Alkarindil, I am looking over the Smaug hometown snippet and I see nothing about town_table in it. What exactly are you putting in?
Brazil #7
Ok.
I will make an example. This is what I am trying to do:
//-----
MUD: Smaug MUD blablabla
Type your name, or type 'new':

Client: new

MUD:Choose a name:

Client: Bilbo

MUD: Bilbo, I get it? [Y/N]

Client: Y

MUD: Choose a password
Client 12345
MUD: Again..
Client: 12345
MUD: Your sex [M/F]
Client: M

MUD: Choose a class: [thief, warrior, ranger]

Client: thief

MUD: Choose a race: [hobbit, human, orc]
//First: an elf here cannot be a thief, alright?
Client: hobbit

MUD: Choose a hometown: [Bree, Hobbiton]
//Second: a hobbit cannot start the game in Mordor.
Client: Bree

MUD: RIP, ANSI or none of then? [A/R/N]
Client: ANSI

MUD: Well done, have a good game, welcome, blablabla...
//-----

I am not using that crimson blade's code, because it seems to doesn't work this way.
Sooo, I **duplicated** some parts of **race's code**, so I can use .town files with restrictions to some races, exactly the way we have classes restrictions in the race's code!

I want a minas_tirith.town file just like this:
---
Name Minas Tirith~
Town 0
Races 14
Language 0
Town_Recall 30000
End
--
Where:
Name: The name.
Town: The town in the smaug code array.
Races: Race restriction. Example: Orcs.
Language: The town's language from the code array.
Town_recall: The room whe can return after death, inside the respective town.

I don't want nations, nor leaders or descriptions. Just hometowns with a race restriction.

It's a test, by now. I am trying to make it work, but I am not understanding why this error ("unresolved external symbol") keep coming!

What kind of files are you talking about? The .c files?
How the hell can I define this damn symbol? I just have two race codes, with different names, different variables. Except the skill's thing. I changed the race's functions to fit the new town's code.

That's it.
Thanks.
Amended on Tue 12 Jun 2007 05:35 PM by Alkarindil
USA #8
I think you need to read a little about C tutorials and what that error message means. You should try googling the error, too. It's actually an extremely simple error to fix.

What it's telling you is that you made reference to a variable that does not exist. You told the compiler it exists, e.g. using an "extern (var type) (var name)" statement but then you failed to actually create it, by using a "(var type) (var name)" statement.

Try it out; in some .c file, write down
extern int silly_variable;

then in a function in the same .c file, say

silly_variable = 3;

and compile, you will get a "unresolved external symbol" error.

Now if you go to another .c file and you write:
int silly_variable;

it will start working. Simple as that...
Brazil #9
David:
You are right!
Horever, deleting the "extern" thing, now I can't list the towns in the registration screen.
Just to remember: it works the same way as races code.
I have only one ".town" file and a "towns.lst" file in a "hometowns/" folder.
I think that maybe it can't list the town's content because of this "extern"'s missing. I don't know...
I am looking for more information, if it work fine, I'll bring the code to the forum.

thanks!
Amended on Wed 13 Jun 2007 10:08 PM by Alkarindil
USA #10
Like I said, I think it would really save you some grief to learn about what these error messages mean. To give you a quick summary, in C(++), a variable always needs to be declared before you can use it. Declaring a variable is telling the compiler that it exists. One way to declare a variable is to define it, e.g. int foo;. That actually creates the physical variable "foo", of type "int".

Another way to declare an integer is to tell the compiler that it exists somewhere else. That is what extern is for: extern int foo;. This tells the compiler that, somewhere else, you have created the physical space for the variable.

The reason you need to use extern is that you don't want several physical copies of a variable. (In fact, the compiler won't let you.) So, you define it in one file by saying "int foo" and in other files, when you want to use it, you say "extern int foo".

But, again, I cannot stress enough how important it would be for you to read up on this properly. Even if it annoys the hell out of you now and you think it's a waste of time, you will gain very, very much in the long run and will be able to solve your problems on your own quickly.
Brazil #11
Alright, I understood.

The line with that problem is:
"extern struct town_type * town_table [MAX_TOWN];"
it's a copy of
"extern struct race_type * race_table [MAX_RACE];"
in mud.h.

The problem to understand it is no more. Now I want to know where is the original race's variable to know if there is some possibility of making a town's similar variable.
I believe it is inside two functions I did not used for town's code. I think I must understand if a c function kills the variable declared inside or not, so I can discover where it is.

Horever, thanks again. I'll keep those things in mind.
USA #12
I think that race_table is defined in const.c. If you are in a Unix-like environment, try:
grep race_table *.c

that will show you every place that "race_table" appears in the code. It will let you find where race_table is defined. Then you can put your town_table definition in the same place.