Thread: Loop Limits
View Single Post
  #1  
Old 01-09-2006, 10:34 AM
Rick Rick is offline
PipBoy Extraordinaire!
Rick's Avatar
Join Date: Jul 2004
Location: Long Beach, California.
Posts: 831
Rick is on a distinguished road
Loop Limits

HTML Code:
function onCreated()
{
  for (temp.npc: findAreaNPCs(0, 0, 64, 64))
  {
    if (temp.npc.isInClass("testobject"))
    {
      temp.npc.destroy();
    }
  }
  
  for (temp.i = 0; temp.i < 100; temp.i++)
  {
    putNPC2(32, 32, "join testobject");
  }
  
  this.loops = 0;
  for (temp.i = 0; temp.i < 100; temp.i++)
  {
    this.loops++;
    
    temp.npcs = findAreaNPCs(0, 0, 64, 64);
    
    for (temp.npc: temp.npcs)
    {
      this.loops++;
    }
  }
}
This code generates a loop limit exceeded error. Yes, I know why - this.loops ends up over 10000.

Can it be changed so that a loop counter of "for (object: objectlist)" loop has less impact on the limit? Or it only starts counting if the list is modified inside the loop?

I'm trying to do something similar to the code above (related to checking for NPCs nearby, etc) but it dies out due to the loop limit.
Reply With Quote