Erasing certain info from a link list.

From: David Cole (tiznor@softhome.net)
Date: 10/24/02


Hello,

I've recently completed the memorize code for spells and with the code I
added a forget command which will enable you to forget certain spells you
have mem'd. Everything with forgetting spells that are memmed works good,
but forgetting things that are in your re-mem list doesn't appear to be as
easy. For some reason (the lines marked) won't work:

ACMD(do_forget)
{
  int spell, i;
  struct SpellMemData *smd;

  skip_spaces(&argument);
  spell = find_spell_num(argument);

  if (!*argument) {
    send_to_char("Syntax: Forget <spell> | all\r\n", ch);
    return;
  } else if (!str_cmp(argument, "all")) {
 for (i = 1; i <= MAX_SPELLS; i++) {
   if (GET_SPELL(ch, i) > 0)
  GET_SPELL(ch, i) = 0;
 }
 ch->MemList = NULL;
 send_to_char("You forget everything!\r\n", ch);
 return;
  } else if ((spell < 1) || (spell > MAX_SPELLS)) {
    send_to_char("You don't have that spell memorized.\r\n", ch);
    return;
  } else {
    if (GET_SPELL(ch, spell) > 0)
   GET_SPELL(ch, spell)--;
 else {
   for (smd = ch->MemList; smd; smd = smd->next) { // Here
     if (smd->spell == spell) // Here
          DeleteMemorieSpell(ch, smd); // Here
   }
 }
 sprintf(BufOne, "You purge '%s' from your thoughts.\r\n",
spell_info[spell].name);
 send_to_char(BufOne, ch);
  }
}

if I only have one spell in my re-mem list is returns a 0x000... on
ch->MemList other wiz if there are more it returns 0x000.... on ch, its
quite odd and I don't understand why this simple thing wont work. below is
DeleteMemorieSpell():

void DeleteMemorieSpell(struct char_data *ch, struct SpellMemData *smd)
{
  struct SpellMemData *temp;

  if (!ch->MemList || !smd)
    return;

  if (smd == ch->MemList) {
    ch->MemList = smd->next;
  } else {
    for (temp = ch->MemList; temp && (temp->next != smd); temp =
temp->next);
    if (temp)
      temp->next = smd->next;
  }

  FREE((char *) smd);
  smd = NULL;
}

Any thaughts or help would be greatly appreciated.
Thanks,
Dave

--
   +---------------------------------------------------------------+
   | 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