|
|
|||||
|
What is a header file?
This is a commonly asked question and at first most people don't value the usefulness of them.
Now first I will assume you looded at some of the code examples. Lets look at the first room we coded....
set_exits(([ "south" : "/realms/petrarch/forest/f_room3.c", "north" : "/realms/petrarch/forest/f_room1.c", ])); I think this is simple to understand. In this room there are 2 exits, one south and one north and after each direction name is the file name of the room you will go to when you move in that direction. Now in this case my Immortal's name is Petrarch and I am coding in my home directory (most likely the only directoy you will have access too) and I don't have access to the /domains/ directory where all areas "in the game" are stored. So in short I code in my own directory, but when my area is completed and moved to the /domains/ those file names are no longer valid becasue instead of
"south" : "/realms/petrarch/forest/f_room3.c", "north" : "/realms/petrarch/forest/f_room1.c", I want
"south" : "/domains/Atheria/forest/f_room3.c", "north" : "/domains/Atheria/forest/f_room1.c", Which means I will need to edit every room for the new exits. If I have 50 rooms, with an average of 3 exits each, thats 150 lines of code to change. Plus, look at our examples for rooms with monsters. We load a monster by file name as well, which means that line needs to be changed. Then look at the code for monsters. Monsters load equipment by file name, and so all those lines need to be changed as well. Now wether you followed that or not I am sure you see that there is a lot involved in changing file names around. So the question is how do we do it easier, and the answer is to use headerfiles. Now beleive it or not, if you based your code on what the examples here are like the you have already used headerfiles.
#include Here you have included a header file called std.h and on the very next line you use it. To understand more, lets first look at the header file std.h
#ifndef __STD_H__ #define __STD_H__ #define ROOM "/std/room.c" #define MONSTER "/std/monster.c" #define OBJECT "/std/object.c" #define ARMOUR "/std/armour.c" #define WEAPON "/std/weapon.c" #define LIGHT "/std/light.c" #define STORAGE "/std/storage.c" #endif Now what does this all mean?
Well the first 2 and the last lines are very important. They insure that you do not #include
Now if you are totally lost, a header file can be made for you by someone else so don't worry about not knowing how to create one.
Well now how to use it?
Well you know that line
inherit ROOM;
Well the header file defines ROOM to be "/std/room.c" so what the MUD sees is...
inherit "/std/room.c";
Where it places the definition in for you. Now this is how a header file is used for you. Lets recode the first room using a header file.
Step 1. Create a Header File (or edit it)
So here is our file.
"south" : FOREST "f_room3.c",
It knows to change that to
"south" : "/realms/petrarch/forest/" "f_room3.c",
Which is the file name we want. So when we code anything that points to another file, we will first define the path of that file in our own headerfile and then use the definition instead.
And how does this help us? Well now when we move files from your realm to the domains all that needs to be changed is the header file. Maybe 6 or 7 lines instead of 100s of lines in 100s of files like before.
Use header files anytime you need to reference another file. So when you include objects or monsters in rooms be sure to use a headerfile to point to that file, don't include the whole path name.
|
|||||
|