Adding a structure to the char_data structure

Posted by Azrith on Wed 12 Mar 2003 09:48 PM — 5 posts, 16,912 views.

#0
Hi! I have added a structure to the char_data structure and everything is compiling fine. However, when Im in the game and a function modifies a value in the new structure it seems to modify all of the character's structures. I believe I probably somehow have the structure tied to all characters but I am not sure how. I added the structure in mud.h and then the line to the struct char_data. Is every character pointing to the same structure? If so how can I get it so that each char has their own structure.
Thanks for the help!

Azrith
Australia Forum Administrator #1
There is one structure, however each character should have a pointer to their own copy of it. Can you post the lines where you modify this new attribute for a particular player, and where you test it?
#2
I finally got it working :) Very strange I originaly setup a table like the race table. Each location the table held the value for a different vehicle. When the character purchase this vehicle I was trying to set their struct mentioned above = to this value. Well for some reason that line was messing things up. Instead of using 1 line I set up a CREATE . . . then the ch->newstruct Then I called a function that set the chars struct = to the vehicle in the proper location of table. That seemed to fix it. :) Thanks for the help though!

Azrith
Australia Forum Administrator #3
The reason is you are dealing with pointers, and using "=" makes a copy of the pointer (ie. you have 2 pointers pointing to the same thing), it doesn't make a copy of the structure it is pointing to.

Using CREATE allocates memory for a second copy of the structure, which is what you want.
#4
Ahh, Thanks! :) That makes some more since now.
I do have another question about a warning when compiling smaug. Its an original warning which Ill just post with a new subject. Thanks again!