Graal Forums  

Go Back   Graal Forums > Development Forums > Tech Support
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 01-09-2006, 02:52 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
It's a little bit complicated, it checks how often a code is executed, not in what kind of loop it is contained. I would say it would be better to optimize the code, but if you can show me a realistic example where the loop limit need to be changed then we can probably add something (loop limit per npc ?)
Reply With Quote
  #3  
Old 01-09-2006, 05:12 PM
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
Quote:
Originally Posted by Stefan
It's a little bit complicated, it checks how often a code is executed, not in what kind of loop it is contained. I would say it would be better to optimize the code, but if you can show me a realistic example where the loop limit need to be changed then we can probably add something (loop limit per npc ?)
Well, I'm trying to write an NPC that creates many NPCs but checks what NPCs are already there... the more NPCs that are around the more quickly the loop limit gets hit.
Reply With Quote
  #4  
Old 01-09-2006, 06:05 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Why exactly are you checking what npcs are already there?
Reply With Quote
  #5  
Old 01-09-2006, 06:46 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Stefan
It's a little bit complicated, it checks how often a code is executed, not in what kind of loop it is contained. I would say it would be better to optimize the code, but if you can show me a realistic example where the loop limit need to be changed then we can probably add something (loop limit per npc ?)
If it checks how often the code is executed, then wouldn't more optimized code trigger it more often than non-optimized code?
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #6  
Old 01-09-2006, 10:06 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Optimizing your script means doing less operations to achieve the same goal
Reply With Quote
  #7  
Old 01-09-2006, 11:53 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Stefan
Optimizing your script means doing less operations to achieve the same goal
But less operations = less time it takes to do them = code gets executed quickly, thus triggering the loop limit?
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #8  
Old 01-10-2006, 01:45 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
x-x less operations = less operations
Reply With Quote
  #9  
Old 01-10-2006, 05:30 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
Quote:
Originally Posted by ApothiX
But less operations = less time it takes to do them = code gets executed quickly, thus triggering the loop limit?
The amount of operations within a loop has nothing to do with the loop limits.
Reply With Quote
  #10  
Old 01-10-2006, 05:34 AM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
>_>
Fighting with Stefan is never good.

What if you add to a level variable when an NPC is created, then subtract from it when it gets destroyed? Less operations. :O
Reply With Quote
  #11  
Old 01-10-2006, 05:45 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
Quote:
Originally Posted by Yen
>_>
Fighting with Stefan is never good.

What if you add to a level variable when an NPC is created, then subtract from it when it gets destroyed? Less operations. :O
What does that have to do with loop limits?
Reply With Quote
  #12  
Old 01-10-2006, 10:08 PM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
Stefan's telling you to optimize it, so the loop limit isn't a problem. :O
DUH!
Reply With Quote
  #13  
Old 01-10-2006, 10:28 PM
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
Quote:
Originally Posted by Yen
Stefan's telling you to optimize it, so the loop limit isn't a problem. :O
DUH!
What you suggested me to do solves nothing in that regard.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:22 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.