> I have in some innate spells which have a duration of -1, however theres a > problem I just noticed in using unaffect, the while loop is called so long > as the victim has affections and I've made it so if the current affect > is -1, it skips it but the loop will keep continuing infinitly.. > > *** > if (victim->affected) { > aff = victim->affected; > while(victim->affected) { > if ( aff->duration > -1 ) > affect_remove(victim, aff); > send_to_char("There is a brief flash of light centered on you!\r\n", > victim); > send_to_char("You negated all of their spells!\r\n", ch); > } > } > > ** Use a for loop instead of a while loop and structure it like this: for (aff = victim->affected; aff ; aff = next) { next = aff->next; if (aff->duration > -1) { affect_remove(victim, aff); /* Messages.... */ } } Obviously "next" must be defined as a pointer to an affected_type structure for the above code to compile. Also note that structuring the loop like this: for (aff = victim->affected; aff; aff = aff->next) { /* THIS IS BAD!!!!!! */ ...etc ...will not work because affect_remove will free the memory associated with aff, and the subsequent loop iteration will cause a crash. Mike -- +---------------------------------------------------------------+ | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html | | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html | +---------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/04/01 PST