Re: Loop Problem

From: Daniel Koepke (dkoepke@CALIFORNIA.COM)
Date: 03/07/98


On Sat, 7 Mar 1998, Wesley Fonvergne wrote:

-> for (i = 0; i << invasion_size; i++) {
->
->   char_to_room(mob, location);
->
->   break;
->
->  }

Two things: that 'break' there will only make it load one mobile.  The
other thing is you want "i < invasion_size" not "i << invasion_size".
The latter--that you have--is a mathematical operation (even in C++,
but certain classes [istream/ostream] use operator overloading to
define new behavior for the operator), and indicates that you should
left shift 'i' by 'invasion_size' bits.  However, the code as you
presented it would not cause the mobiles to load forever.  It would
only load one mobile, even if you took out the 'break;' statement
because of the fact that when i = 0, i << invasion_size will also
equal 0 and thus, "i << invasion_size" is false (0) and the loop ends.
So, either you've changed the code since it loaded mobiles repeatedly,
or you have posted the wrong code, or you just didn't identify the
behavior correctly.

In addition, it's not desirable to do "char_to_room(mob, location);"
more than once with the same mobile.  You probably want code
equivalent to,

  mob = read_mobile(mob_rnum, REAL);
  char_to_room(mob, room_rnum);

Of course, using your variables in place of mine.  How you have it,
you are doing char_to_room() for the same one mobile over and over
again, which I doubt is what you want to do (that means that the
character ends up in the list invasion_size amount of times, but it's
still only one character, and will probably cause a crash).


-dak


     +------------------------------------------------------------+
     | 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/15/00 PST