What's the purpose of the %stackmoved variable? I'm having a hard time making the math work in my head about what happens every time you iterate through the FOR statement and you're adding that to #FINDCNT each time.
Suppose you have 3 tools matching the color 1165 with 7 total in the pack and a stackmoved value set to 10(for example)
%crafted = 0
in the for loop:
found 1: %crafted = #findcnt + %stackmoved --> %crafted = 7 + 10 = 17
found 2: %crafted = #findcnt + %stackmoved --> %crafted = 7 + 10 = 17
found 3: %crafted = #findcnt + %stackmoved --> %crafted = 7 + 10 = 17
Don't you want it to work more like this:
%crafted = 0
in the for loop:
found 1: %crafted = %crafted + 1 --> %crafted = 0 + 1 = 1
found 2: %crafted = %crafted + 1 --> %crafted = 1 + 1 = 2
found 3: %crafted = %crafted + 1 --> %crafted = 2 + 1 = 3
%crafted = %crafted + %stackmoved --> 3 + 10 = 13
??
You probably need to put a "pause" at the beginning of your function, and setup watch points of your variables and then single step through your code to make sure it's working the way you think it should be.
sub FindColoredItem
namespace push
namespace local FCI
set !finditem %1
set !container %2
set !color %3
set %crafted 0
finditem !finditem C_ , !container
if #FINDCNT > 0
{
for #FINDINDEX 1 #FINDCNT
{
if #FINDCOL = !color
{
set %crafted %crafted + 1
set #LOBJECTID #FINDID
}
}
}
set #RESULT %crafted + %stackmoved
Menu Font Size 10
Menu Font Color Black
menu set Crafted %crafted
namespace pop
return #RESULT