> I'm trying to create surnames, and masks, by masks I mean... > > A character can type: mask <text> and this will be displayed instead of the: > > Name Surname Title Position > Dumbo Dinky the Elephant is standing here. > > Instead of the characters lising like this, I'd want to have the mask (skill > maybe, but maybe for everyone) > > Name Surname Mask > Dumbo Dinky is walking around aimlessly. <-- user defined > I would recommend that you mimic the code relating to 'title' - and i'm sure you already realize that altering the char_file_u structure to have this actually save will invalidate your current player file. As for the cases where this is 'NULL', just check for that and if it is, don't display it. > > So, I dont understand what is going on with that. I dont know how to explain > it more than that. Another thing that I dont get... is why do I need to use > the CREATE macro, like with the name of the character, when you dont need to > use it for everything else. If I add new ch->points or anything in the > player_saved, I dont need to call CREATE for it... If someone could stick me > in my place for this one, then that would be great. > Ouch. Okay, as George said in his email, you need a c book, but because I'm in a rather good mood today, I'll get you started on this. I may not be 100% accurate, but it shouldn't be so off as to cause any problems. - Begin remedial C lesson - All variables take up memory. Integers, chars, floats, whathave you, all exist as in memory. The most common usage of this memory is automatic: int a; /* allocate space for one integer type variable */ char message[128]; /* allocate consecutive space for 128 chars */ etc. Now, here's where your confusion is coming in - pointers! Pointers are magical things and yes, they have their own size. However, the size of the pointer itself has very little to do with the size of the thing it's actually pointing to. When you type: char *message; You're allocating space for a pointer. Lets say your message is 100 characters long. Well, you can't just do a string copy. There's no way you could fit a block of contigious memory in a space designed for a single pointer. Instead, you have to allocate the memory. message = calloc(100,sizeof(char)); or maybe this is more recoginizable CREATE(message,char,100); Now, you can copy that string into the address designated by the pointer, since you've now allocated space for it. strcpy(message,"This is a 100 character long message, maybe."); With strings, there's already a library function that will allocate the memory and everything for you, so you can skip your alloc step. It's called strdup. Use like this: message=str_dup("this is a 100 character long message, maybe."); Aside from the fact that this is rather important in and of itself, you'll notice that any structure that is written out directly to disk (like your player files from char_file_u) don't have these pointers in them. Matter of fact, they're all non-dereferenced instances (* is your dereferencing operator). This is because when writing out the structure it writes it out in a chunk that is the size of the structure. If the structure has an eighty character array in it, 80 characters of space are set aside. If it's just a pointer, then only the space of one pointer will be set aside. And as we already learned, you can't store too much in the space of a single pointer. This lesson was brought to you by the man pages 'malloc', 'calloc', 'strcpy', 'strdup', and the dereferencing operator *. - end remedial c lesson - (the '*' is the dereferencer right? I always get those two names mixed up..) PjD +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST