Server Help

ASSS Custom Projects - Some kind of infinite loop

Smong - Tue Apr 15, 2003 2:56 am
Post subject: Some kind of infinite loop
I'm trying to make a race module. When ?race is typed it checks to to see if anyone is in the start box and adds them to its internal list of drivers, then it starts the race. If I'm not in the box everything is OK. But when I go into the box it adds me to the list then locks-up/goes into an infinte loop. Can anyone see what is wrong with my code?
Code: Show/Hide

#define maxDrivers   6

typedef struct {
   Player *p;
   int active;
   int chkpt;
   int lap;
   int kills;
   float times[11];
} Driver;

local Driver dvr[maxDrivers];

//Requires chat, pd and mainloop
local void startRace() {
   int drivers=0, i;
   Link *link;
   Player *p;
   if (!pd) return; //Safety
   if (!chat) return; //Safety
   lm->Log(L_INFO, "<hio> Adding players to race:");

   pd->Lock();
   FOR_EACH_PLAYER(p) {
      //In starting area?
      if (!inArea(startBox, p)) {
         lm->Log(L_DRIVEL, "<hio> [%s] not in start box", p->name);
//         continue;
      } else

      //PM if not enough slots
      if (drivers >= maxDrivers) {
         lm->Log(L_DRIVEL, "<hio> [%s] race full", p->name);
         chat->SendMessage(p, "This race is full, sorry");
//         continue;
      } else

      //Add to race
      for(i=0; i<maxDrivers; i++) {
         if (dvr[i].active == 0) { //== 1) continue;
         drivers++;
         dvr[i].active = 1;
         dvr[i].chkpt  = 1;
         dvr[i].lap    = 0;
         dvr[i].kills  = 0;
         dvr[i].p      = p;
         lm->Log(L_INFO, "<hio> [%s] added to race", p->name);
         chat->SendMessage(p, "Get ready to race...");
         i = maxDrivers; //break;
         }
      }
   }
   pd->Unlock();

   //Ready? Go Go Go!
   lm->Log(L_INFO, "<hio> Starting race...");
   if (mainloop)
      mainloop->SetTimer(checkCheckpoint, 100, 120, NULL, p->arena);
   chat->SendArenaMessage(p->arena, "Go Go Go!"); //104

   //Set time()
/*   for(i=0; i<maxDrivers; i++) {
      if (dvr[i].active == 0) continue;
      dvr[i].lstime = time();
   }*/
   //lm->Log(L_INFO, "<hio> Race in progress");
}

I replaced all break/continues with else just incase it was breaking/continuing the wrong bit of code.
Mine GO BOOM - Tue Apr 15, 2003 10:53 am
Post subject:
Upload full file so can debug locally. What debugging are/can you use?

If cannot upload full file, when is startRace called? Place some debugging messages throughout loops, or run in a debugger locally with breakpoints around certain code points in the source to see which loop breaks, and what some of the variables contain for values.
Smong - Tue Apr 15, 2003 4:04 pm
Post subject:
I found it, "chat->SendMessage(p, "Get ready to race...");" was inside a pd->Lock()/Unlock().
That means I will also have to remove "chat->SendMessage(p, "This race is full, sorry");"
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group