Author Topic: A quick question about a better way to do this For loop useing #findindex.  (Read 2336 times)

0 Members and 1 Guest are viewing this topic.

Offline AlphaTopic starter

  • Hero Member
  • *
  • Posts: 583
  • Activity:
    0%
  • Reputation Power: 10
  • Alpha barely matters.Alpha barely matters.
  • Respect: +44
  • Referrals: 0
    • View Profile
OK...   so I find myself making this mistake occasionally & I'm looking for a good way to get around it.. 
Example
Code: [Select]
;-----------------------------
finditem yfm
For #findindex 1 #findcnt
  {
      Gosub Check_Item #findid     ;--%1 is #findid of Item to Check
  }
;-----------------------------

The problem that I always cause myself is that I inevitably perform ANOTHER finditem command inside the Gosub which then messes up my #findindex so that the next time it performs the FOR loop the #findid sent as %1 is invalid.   I use this sort of structure alot & usually try to keep finditems OUT of the Gosub, but there's gotta be something simple to fix this heh.   Thx.

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13303
  • Activity:
    0.4%
  • 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
0
Unfortunately there is no real easy way to fix this other than being really careful with how you have your script execution organized.  Actually, in those instances, I'll don't rely on #FINDINDEX, and just iterate through a fresh FINDITEM.  It's slower, but you don't miss anything by accidentally/purposefully running another FINDITEM.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Dixie Wrecked

  • Full Member
  • ***
  • Posts: 124
  • Activity:
    0%
  • Reputation Power: 3
  • Dixie Wrecked has no influence.
  • Gender: Male
  • Respect: +31
  • Referrals: 1
    • View Profile
0
Would something like this solve your problem, where you would load the IDs of each item into an array like %item1, %item2, %item3, etc, as well as the #findcnt into a %count variable, then use thes loaded variables in the loop, thus allowing you to do additional finditems without losing the original values:

Code: [Select]
finditem yfm
set %count #findcnt
for #findindex 1 %count
  set %item . #findindex #findid
For %loop 1 %count
  {
      Gosub Check_Item %item . %loop     ;--%1 is #findid of Item to Check
  }

I would probably change the variables to something more relevant to the script, but otherwise, this seemed to work in a quick test for me?
"hmm, theres no examples and directions sticky in new member intros.  you have to admit script library would have been a good place to put it"
- karrde

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13303
  • Activity:
    0.4%
  • 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
0
That's a great solution, Dixie.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline AlphaTopic starter

  • Hero Member
  • *
  • Posts: 583
  • Activity:
    0%
  • Reputation Power: 10
  • Alpha barely matters.Alpha barely matters.
  • Respect: +44
  • Referrals: 0
    • View Profile
0
Yeah that's just what I was looking for....  I "get" arrays if I think about em but I don't intuitively understand them so I have to work at coming up with uses for them.  I literally had to check what the DOT operator did for a second bc I was saying in my head   "It appends the value of the variable following the DOT into the Variable B4 the DOT" lol which isn't the case.  Actually = "appends the value following the DOT to the END of the Variable B4 the DOT"   Anway that's what I needed!

Tags: