Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ Adding a structure to the char_data structure
Adding a structure to the char_data structure
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Azrith
(15 posts) Bio
|
Date
| Wed 12 Mar 2003 09:48 PM (UTC) |
Message
| 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,162 posts) Bio
Forum Administrator |
Date
| Reply #1 on Thu 13 Mar 2003 09:54 PM (UTC) |
Message
| 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? |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Azrith
(15 posts) Bio
|
Date
| Reply #2 on Fri 14 Mar 2003 07:43 PM (UTC) |
Message
| 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,162 posts) Bio
Forum Administrator |
Date
| Reply #3 on Fri 14 Mar 2003 09:34 PM (UTC) |
Message
| 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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Azrith
(15 posts) Bio
|
Date
| Reply #4 on Sat 15 Mar 2003 06:38 AM (UTC) |
Message
| 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!
| Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
14,128 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top