> > On Sat, 4 Oct 1997, Andrew Helm wrote: > > SNIP > > Okay, what I mean is.. I have an array in the pfile.. int memorized[100]; > which stores spellnums, if they forget a spell, I want it to set the > spellnum to 0, and if there is a 0 in the array, I want it to move all > entries to the left one after the zero, so there are no more zeros until > the end of the array > i.e. > 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 5 > would equal this: > 1, 2, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 This is mailer code. You've been warned. When you first make the array be sure to initialize every entry to zero. #define MAX_MEMORIZED 100 #define MEMORIZED(c) how to get the memorized array from the player here Note: the array should be declared as int array[MAX_MEMORIZED] int memorize_spell(struct char_data *ch, int spellnum) { unsigned int i; for (i = 0; (i < MAX_MEMORIZED) && MEMORIZED(ch)[i]; ++i) ; if (i == MAX_MEMORIZED) return 0; MEMORIZED(ch)[i] = spellnum; return 1; } int forget_spell(struct char_data *ch, int spellnum) { unsigned int i; if (spellnum == 0) return 1; for (i = 0; (i < MAX_MEMORIZED) && (MEMORIZED(ch)[i] != spellnum); ++i) ; if (i == MAX_MEMORIZED) return 0; if (i != MAX_MEMORIZED - 1) { for (; (MEMORIZED(ch)[i] = MEMORIZED(ch)[i + 1]) && (i < MAX_MEMORIZED - 1); ++i) ; MEMORIZED(ch)[i + 1] = 0; } MEMORIZED(ch)[MAX_MEMORIZED - 1] = 0; return 1; } +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/08/00 PST