Question

Login to reply  Page: « < 1 of 1 > »
22 Aug 2010 - 13:242949
Question
void make_dball(struct char_data *ch) { room_rnum location = NOWHERE; int infinite_loop = 0; struct obj_data *dball; while (location == NOWHERE && infinite_loop < 5000) { location = real_room(number(100, 158)); infinite_loop++; } dball = read_object(1201, VIRTUAL); obj_to_room(dball, location); }
I wrote this code awhile back. It's a scattering code for a dragonball. I was taking it look at it and notice that it can only scatter to rooms 100-158.




while (location == NOWHERE && infinite_loop < 5000) { location = real_room(number(100, 158)); infinite_loop++; }

I was wondering if there is a way I can change that so it finds all rooms created already and randomly picks one to assign the item too? Thanks.


__________________
Owner/Admin/Programmer - Drag(*)nball Z: Paradox
23 Aug 2010 - 20:262950
Your method certainly is ... interesting...

try


 location = number(0, top_of_world-1);


__________________
You know who I am.
24 Aug 2010 - 00:292951
Question
Quote Rikishi:

void make_dball(struct char_data *ch)
{
 room_rnum location = NOWHERE;
 int infinite_loop = 0;
 struct obj_data *dball;
 
 while (location == NOWHERE && infinite_loop < 5000) {
     location = real_room(number(100, 158));
     infinite_loop++;
 }
 
 
 dball = read_object(1201, VIRTUAL);
 obj_to_room(dball, location);

}


Just curious, not a criticism... why name the variable "infinite_loop" when it clearly isn't?

My suggestion on how to revamp this to something more standard for CircleMUD/tbaMUD (This is off the top of my head w/out any reference material, I don't remember if the world table is rnums of vnums at the moment, so this may not be 100% accurate, pretty darn close though. Plus it scatters all 7 dragonballs :D):
/* This will scatter all 7 Dragon Balls! NOTE: Existing Dragon Balls should be removed prior to use! */
void make_dball(struct char_data *ch)
{
  room_rnum location = NOWHERE;
  int i = 0, ball = 0;
  struct obj_data *dball;

  for (i = 0; i < 5000, ball < 7; i++) {
    if ((location = real_room(number(0, top_of_world -1)) != NOWHERE) {
      dball = read_object(1201, VIRTUAL);
      obj_to_room(dball, location);
      ball++;
    }
  }
}


__________________
Owner/Coder/Head Admin
Caer Dubrin

Last edited by ralgith (24 Aug 2010 - 00:47)
Login to reply  Page: « < 1 of 1 > »