Code:
ReadNumber(path = "img\num\inv_gold\", x1=1455,y1=510 , x2=1572, width_digit=9, height_digit=12,tolerance=5){ ; default : gold in inventory
amount:=0
SleepRand(100,10)
y2:=y1+height_digit
s1:=path . "1.png", s2:=path . "2.png", s3:=path . "3.png", s4:=path . "4.png", s5:=path . "5.png"
s6:=path . "6.png", s7:=path . "7.png", s0:=path . "0.png", s8:=path . "8.png", s9:=path . "9.png"
If !(FileExist(s1) AND FileExist(s2) AND FileExist(s3) AND FileExist(s4) AND FileExist(s5) AND FileExist(s6) AND FileExist(s7) AND FileExist(s8) AND FileExist(s9) AND FileExist(s0)){
return -1
}
Loop {
d:=-1
xtemp:=x2
if ImageSearchArea(s1, x, y, tolerance, x1, y1, x2, y2) {
if (x < xtemp) {
xtemp:=x
d:=1
}
}
if ImageSearchArea(s2, x, y, tolerance, x1, y1, x2, y2) {
if (x < xtemp) {
xtemp:=x
d:=2
}
}
if ImageSearchArea(s3, x, y, tolerance, x1, y1, x2, y2) {
if (x < xtemp) {
xtemp:=x
d:=3
}
}
if ImageSearchArea(s4, x, y, tolerance, x1, y1, x2, y2) {
if (x < xtemp) {
xtemp:=x
d:=4
}
}
if ImageSearchArea(s5, x, y,tolerance, x1, y1, x2, y2) {
if (x < xtemp) {
xtemp:=x
d:=5
}
}
if ImageSearchArea(s6, x, y, tolerance, x1, y1, x2, y2) {
if (x < xtemp) {
xtemp:=x
d:=6
}
}
if ImageSearchArea(s7, x, y, tolerance, x1, y1, x2, y2) {
if (x < xtemp) {
xtemp:=x
d:=7
}
}
if ImageSearchArea(s8, x, y, tolerance, x1, y1, x2, y2) {
if (x < xtemp) {
xtemp:=x
d:=8
}
}
if ImageSearchArea(s9, x, y, tolerance, x1, y1, x2, y2) {
if (x < xtemp) {
xtemp:=x
d:=9
}
}
if ImageSearchArea(s0, x, y, tolerance, x1, y1, x2, y2) {
if (x < xtemp) {
xtemp:=x
d:=0
}
}
if (d=-1) { ;no digit found
break
}
x1:=xtemp+width_digit-1
if (amount=0) {
amount:=d
}
else {
amount := 10 * amount + d
}
}
return amount
}
btw, this is my ImageFind function;
Code:
ImageSearchArea(img, ByRef x, ByRef y, tolerance=0, x1=0, y1=0, x2=1920, y2=1080) { ; return 1 if found
If (tolerance > 0) img := "*" . tolerance . " " . img
img := "*TRANSBLACK " . img
ImageSearch, x, y, x1, y1, x2, y2, %img%
if (ErrorLevel = 0) {
return 1
}
else {
return 0
}
}