From: "Joe Mann" <LightKnight@aol.com>
> Hey, I am trying to write a piece of code that will allow players to
change their description in game using a command like:
> desc You see a tall person with dark hair.
> Here's what I have:
>
> ACMD(do_desc)
> {
> skip_spaces(&argument);
> if (!*argument) {
> if (!ch->player.description)
> send_to_char("You have no description!\r\n", ch);
> else {
> sprintf(buf, "Your current description is:\r\n%s",
ch->player.description);
> send_to_char(buf, ch);
> }
> }
> else {
> ch->player.description = argument;
This is the part you're getting problems with. You're assigning a pointer
to point to a global buffer. Remove the line above - What you want here is:
if (ch->player.description)
free(ch->player.description);
ch->player.description = str_dup(argument);
This will deallocate any memory already used, and then create a copy of the
string at the 'argument' position in memory. This way, when people use other
commands (which might use the 'argument' pointer), the description won't be
touched.
> sprintf(buf, "Your description has been changed to:\r\n%s",
ch->player.description);
> send_to_char(buf, ch);
> }
> }
>
Welcor
--
+---------------------------------------------------------------+
| FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
| Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
| Newbie List: http://groups.yahoo.com/group/circle-newbies/ |
+---------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 06/25/03 PDT