Author Topic: #findindex iteration limit  (Read 3012 times)

0 Members and 1 Guest are viewing this topic.

Offline GemviperTopic starter

  • Sr. Member
  • *
  • Posts: 481
  • Activity:
    0%
  • Reputation Power: 0
  • Gemviper hides in shadows.
  • Respect: +57
  • Referrals: 2
    • View Profile
#findindex iteration limit
« on: January 31, 2017, 11:03:47 PM »
0
Working on something way past my bedtime again...

I am performing a finditem and iterating through the results with a #findindex but during a couple of tests I realized there is a delay before doing anything if the #findcnt of my search has found too many items. That's expected, the #findindex is needing to process what was found one by one. It dawned on me however that there is no need to iterate through EVERY result, by limiting it to the first 50 or so I could eliminate the initial pause before the script does something. (well, not eliminate, just break it up so as not to procrastinate so long at the start!)

If finditem finds 1000 results how do I best limit it to processing only the first 50 via a #findindex loop? I do use continue as a filter but the sheer volume sometimes leads to prolonged inaction. I also wouldn't need to tell it to check the next 50 and so on afterwards until the 1000 are processed because when it's done acting on the first 50 it could be run again. Call it chunking if you will, and 50 is an arbitrary number, I'd fine tune it based on results.

Is there a command for limiting how many of the finditem results will be processed with #findindex if the #findcnt is exceedingly high, say 1000+ ?


Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: #findindex iteration limit
« Reply #1 on: February 01, 2017, 10:28:50 AM »
0
You should be able to break it up into chunks.  Just have a start and an end variable, and when you're done with one chunk, replace the start with the last end (+1) and iterate through the next 50 or whatever.  As long as you don't do another finditem, the list addressed by the last #FINDINDEX/#FINDCNT should remain.  Finally just set a flag that says you are iterating through a bunch of items, and clear that flag once your #FINDINDEX reaches the #FINDCNT so you can use finditem again.

Because I was bored (very untested also)

Code: [Select]

repeat
  if %idle = #TRUE
  {
    finditem %list G_20
    if #FINDCNT > 0
    {
      set %idle #FALSE
      set %start_index 1
      set %end_index #FINDCNT
      if %end_index > %chunksize
        set %end_index %chunk_size
    }
  }
  else
  {
    for #FINDINDEX %start_index %end_index
    {
      if #FINDID = (whatever)
      {
        ; do something interesting
      }
    }
    set %start_index %end_index + 1
    set %end_index %end_index + %chunk_size
    if %end_index > #FINDCNT
      set %end_index #FINDCNT
    if %start_index > #FINDCNT
      set %idle #TRUE
  }
  ; do the normal loop
until #FALSE
« Last Edit: February 01, 2017, 10:45:10 AM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline BobOzarius

  • Full Member
  • ***
  • Posts: 103
  • Activity:
    0%
  • Reputation Power: 2
  • BobOzarius has no influence.
  • Respect: +26
  • Referrals: 0
    • View Profile
Re: #findindex iteration limit
« Reply #2 on: February 01, 2017, 11:53:16 AM »
0
Code: [Select]
for #findindex 1 50

Offline GemviperTopic starter

  • Sr. Member
  • *
  • Posts: 481
  • Activity:
    0%
  • Reputation Power: 0
  • Gemviper hides in shadows.
  • Respect: +57
  • Referrals: 2
    • View Profile
Re: #findindex iteration limit
« Reply #3 on: February 03, 2017, 04:02:29 AM »
0
Thanks for both those suggestions, each gave me an idea!
« Last Edit: February 03, 2017, 04:04:35 AM by Gemviper »

Tags: