ScriptUO
Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Alpha on January 20, 2011, 09:02:30 AM
-
OK... so I find myself making this mistake occasionally & I'm looking for a good way to get around it..
Example
;-----------------------------
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.
-
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.
-
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:
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?
-
That's a great solution, Dixie.
-
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!